Captain Paralytic schreef:
On 26 Jun, 16:04, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
>Tony B schreef:
>>I have a string in a existing php script which is in the form "dd/mm/yyyy"
and I need to convert it into a suitable format for mysql which is
"yyyy-mm-dd" Is there a neat way of doing this in php ?
Hi,
I always do this 'by hand', eg:
$orgDate = "22/06/2008";
$partsArr = explode("/",$orgDate);
$newDate = $partsArr[2]."-".$partsArr[1]."-".$partsArr[0];
If you think the above method sucks, you can also do this:
You can also make a Unix Time Stamp of the original date, and use date()
to parse it to a format you need:
parse a date to UTS:http://nl.php.net/manual/en/function.strtotime.php
date:http://nl.php.net/manual/en/function.date.php
Regards,
Erwin Moller
Erwin that all seems an awful lot of work when MySQL supplies the
STR_TO_DATE function specifically to do this job!
http://dev.mysql.com/doc/refman/5.0/...on_str-to-date
Yes I know. Or more honest: I expected MySQL had it (I don't use MySQL,
only Postgresql, which of course has it all.)
I can only say I don't trust datehandling.
I live in Europe/Netherland, and over here 05/06/2008 means 5 june 2008
for example.
My server however is configured USA style.
Next country has different notation.
So when I throw the string "2008/06/05" at you, what does it mean?
And what does it mean in Bulgary? Or India?
I always found working with dates very confusing.
When I work on dates I am always double/triple check, especially when
users provide the strings, or they come for some external source.
I once extended an existing employee-time-declare system so their bosses
could accept or reject declared hours for Philips. The users where
traveling all over the world, through timezones, etc. It was a total
confusing disaster, especially because the employees entered their
dates/times themself.
I guess I picked up the habbit of handling dates myself in that time.
Anyway, all excuses. You are right of course.
I don't have to impose my date-paranoia on others. ;-)
Regards,
Erwin Moller
PS: I know my explode-like solution doesn't solve the 2008/06/05
month/day problem.
Nowadays, when I get dates in from clients, I simply avoid using e TEXT
field, but use dropdowns with months/days/years, so they cannot do it
wrong. Oh well, it is HARDER for them to do it wrong. ;-)