General timestamp?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
lcidw
Forum Commoner
Posts: 58
Joined: Mon Apr 28, 2003 8:55 am
Location: Netherlands

General timestamp?

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply