Re: strtotime problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





From your function name I assume you want to use it in MySQL. In that case, why don't you have MySQL do all the magic for you?
eg. INSERT INTO table (col) VALUES (FROM_UNIXTIME($timestamp));
(using FROM_UNIXTIME($timestamp) will give you the date-time in "mysql format" (YYYY-MM-DD HH:MM:SS) or any other format (if given via the 2nd parameter)


Well I have made these two functions to solve this:

function dateMysqlToWeb($mysqldate){

   $format = 'd/m/Y';
   $timestamp = strtotime($mysqldate);

   return date($format,$timestamp);

}

function dateWebToMysql($webdate){
$format = 'Y-m-d';
   $date_part = explode("/",$webdate);
   $timestamp = mktime(0,0,0,$date_part[1],$date_part[0],$date_part[2]);

   return date($format,$timestamp);

}

My basic problem was how to make the user input from a form into a timestamp not how to use it with mysql. Since the format used here is dd/mm/yyyy I can't use the strtotime directly bacause as far as I know from the documentation I don't think that it changes with the timezone (as Stut suggested). So since strtotime understands all these variations like:

mm/dd/yyyy, m/d/yy, mm/d/yy etc

I can't use this flexible behavior to get the input if it is not in the American format (and correct me if I am wrong). If I explode I will have to use the fixed format dd/mm/yyyy and I can't use other input formats beside this so I lose this flexible approach.

It does work for me now but I was wondering if there was a way to avoid this.

--
Thodoris


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux