Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting date into mysql

Status
Not open for further replies.

bopritchard

Programmer
Jan 27, 2003
199
US
i realize i shouldn't be having this much trouble with this but....

i'm just inserting a row into a mysql table...the date is in the format mm/dd/yyyy and of mysql wants it as yyyy/mm/dd

what's the easiest way to handle this...
mysql function on the insert statement?
php function?

thanks
 
I'd handle it in PHP.

This code:

Code:
<?php

$a = '12/13/2004';

print substr($a, 6, 4) . '-' . substr($a, 0, 2) . '-' . substr($a, 3, 2);

?>

Outputs:

2004-12-13







Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I'd use strtotime() and date()
Code:
$date = '12/13/2004';
$mysql_date = date('Y-m-d',strtotime($date));

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top