Hi Guys,
How do I convert a date in mmddyy format (ie: 251207) into a MySQL timestamp in following format: 2008-12-25 00:00:00
The main thing is that the date gets converted like above, I am not concerned about the time.
Thanks in advance.
| SitePoint Sponsor |
Hi Guys,
How do I convert a date in mmddyy format (ie: 251207) into a MySQL timestamp in following format: 2008-12-25 00:00:00
The main thing is that the date gets converted like above, I am not concerned about the time.
Thanks in advance.

explode
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">



If you are certain the date will always be in that format you could do -
Where is the date coming from? User input?PHP Code:<?php
$dte = '251208';
$day = $dte[0].$dte[1];
$mnth = $dte[2].$dte[3];
$yr = $dte[4].$dte[5];
printf("20%s-%s-%s 00:00:00",$yr,$mnth,$day);
?>
Is the ddmmyy date actually used in the script logic? Could you just use mysql's date time functions to generate a correctly formatted date in the first place?
Hi,
Instead of using printf to show the output, how do I save the output as a variable?
How about like this?
PHP Code:$string = "251207";
$date = "20" . substr($string, 4, 2) .
"-" . substr($string, 2, 2) .
"-" . substr($string, 0, 2);
$date = date('Y-m-d H:i:s', strtotime("$date"));
echo $date;
Bookmarks