Re: date conversions

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

 



Yeah, this is my problem with relyinig on strtotime().  If you don't give it a format that it knows, it's going to give you random results (well, not random, but "undesireable").  Seems like more of a crutch that leaves too much chance of error for my taste.  I prefer to be a little more explicit:


$testdate="30/11/2004";
list($day,$month,$year) = explode("/",$testdate);
echo date("Y-m-d", mktime(0,0,0,$month,$day,$year));

Try that out.  mktime() produces a serial date/time just like strtotime() but you have a little more control over what it's producing and subsequently what gets piped into date().  This exact example is what I used once before when arguing against using strtotime().  Most people are going to use a 'normal' format that strtotime() likes, but the format you're using (european standard?) and just using the numbers is the one big instance that strtotime() breaks.

Hope this helps.  You should be able to get whatever date format you need now.

-TG

*** new email address tg-php@xxxxxxxxxxxxxxxxxxxxxx
*** old email address tgryffyn@xxxxxxxxxxxxxxxxx YAY CHAPTER 11!  :(




= = = Original message = = =

Hi

I am needing to convert a d/m/y date such as 30/11/2004 into the format that
mysql can use ie. 2004-11-20

If I try the following:

$testdate="30/11/2004";
echo date("Y-m-d", strtotime($testdate));

the result is - 2006-06-11

I can't find any other function apart from strtotime to do this.

Any ideas?

Thanks
Neil


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux