At 3:04 PM -0800 2/6/01, Richard Scott Crawford wrote:
>Cold Fusion has a wonderful function called CreateODBCDate(), which
>takes as an argument any date in just about any format and returns a
>standard ODBC date format that you can plug into a database without
>worrying about conversion.
>
>Does PHP have a similar function? I've looked for one but can't
>seem to find it anywhere.
From
http://www.php.net/manual/en/function.strtotime.php
-
"strtotime - Parse about any english textual datetime
description into a UNIX timestamp"
If the ODBC timestamp looks like
yyyy-mm-dd hh:mm:ss
then you could do:
$Date = '1 jan 2001';
ODBCDate = date('Y-m-d H:i:s', strtotime($Date));
And if you really want, just define the function
function CreateODBCDate($DateString)
{
return date('Y-m-d H:i:s', strtotime($DateString));
}
and you can ease your CF-PHP transition :)
If you want to default to returning the current date:
function CreateODBCDate($DateString='')
{
return
(
$DateString ?
date('Y-m-d H:i:s', strtotime($DateString)) :
date('Y-m-d H:i:s')
);
}
Sorry about the weird indent style --- I was trying to avoid wordwrapping.
It doesn't specify in the docs, but I _assume_ strtotime() returns
false if it can't figure out what the date string is...you might want
to test that.
- steve
>--
>Richard Crawford (mailto:[EMAIL PROTECTED])
>http://www.mossroot.com AIM Handle: Buffalo2K
>"Tomorrow, we'll seize the day and throttle it!" -Calvin
--
+--- "They've got a cherry pie there, that'll kill ya" ------------------+
| Steve Edberg University of California, Davis |
| [EMAIL PROTECTED] Computer Consultant |
| http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ |
+-------------------------------------- FBI Special Agent Dale Cooper ---+
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]