Page 1 of 1

General timestamp?

Posted: Mon Jun 16, 2003 9:23 am
by lcidw
I am trying to create code which creates a timestamp in a form i can put into a database, and the database will read and convert to TIMESTAMP format.

The two different databases i use are MySQL and DB2. As far as i have found i need to specify two different input codes formats..

..but how in Micheal Schumacher's name can i convert a date with this format..

Code: Select all

2003-12-31
I tried date(), mktime() and all other, i just cannot do it. Can someone tell me how i should use it, to convert it to a timestamp a database wants?

Posted: Mon Jun 16, 2003 10:07 am
by twigletmac
You can split it up into it's component parts using explode():

Code: Select all

$date = '2003-12-31';
$date_parts = explode('-', $date);
and then glue it back together in which ever format your database requires:

Code: Select all

// yyyymmdd:
$date_db1 = implode('', $date_parts);

// mm/dd/yyy
$date_db2 = $date_parts[1].'/'.$date_parts[0].'/'.$date_parts[2];
Mac