Re: date conversions

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

 



Interesting use of split().. don't think I've ever used that function but looks like it'll do just as well and also allow multiple dividers.  Thanks for pointing that out.

As for this:

$mysqldate = $y.'-'.$m.'-'.$d;


The only problem I foresee is what happens when you have single digit days and months?

2004-9-8

What does MySQL do with this?

What happens if you want the date in another format?  It'll take another minute or two (and leave more potential for typing errors I think) if you did your date format like this rather than using date() + mktime().   I think date/mktime gives you more reliability and more flexibility.   Just something to think about.  When it comes down to it, whatever works for you, right? :)

-TG

= = = Original message = = =

Thank you for all your help.

Among all  the variations I found this to be the clearest:

list($d,$m,$y) = explode("/",$testdate);
$mysqldate = date("Y-m-d", mktime(0,0,0,$m,$d,$y));

But I also thought the use of split instead of explode so you could nominate
multiple delimiters was good.
eg.
list($d,$m,$y) = split('[/.-]', $testdate);

Another variation was to hardcode the date results instead of using the date
function which is very simple:
eg.
$mysqldate = $y.'-'.$m.'-'.$d;

Sorry for asking a question that is obviously asked often.

Interesting comment on 'normal'. I suspect that numerically more of the
world uses dmy than mdy. There is a lot more of the world outside the US
than in it.

Thanks again for all your help.

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