j_k
asked on
Date format
In working with date fields in Php/MySql - the format for date storage is YYYY-MM-DD. Are there any functions to convert this format to MM-DD-YYYY when displaying the date in an html form, but convert it back to YYYY-MM-DD before writing to the database.
ASKER
Rob,
Date('m-d-Y',$now); always returns 12-31-1969 regardless of $now's value. I hope it is a simple fix!
Jak
Date('m-d-Y',$now); always returns 12-31-1969 regardless of $now's value. I hope it is a simple fix!
Jak
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or as freshmeat wants to say...RTFM! ;)
A simple answer to this Q is that you only need to output the date on the HTML site. So only this is used :
echo date( "M-d-Y", mktime(0,0,0,1,1,1999) );
output : Jan-01-1999
Joseph
A simple answer to this Q is that you only need to output the date on the HTML site. So only this is used :
echo date( "M-d-Y", mktime(0,0,0,1,1,1999) );
output : Jan-01-1999
Joseph
Here's a nasty fix :
<?
//$date is a date like '1999-12-31'
$year = substr($date,0,4);
$month = substr($date,5,2);
$day = substr($date,8,2);
$newdate = $day.'-'.$month.'-'.$year;
?>
So, $date is the start date where each month and day must be two characters, eg 02, 11 etc. and puts the formatted date in $newdate.
<?
//$date is a date like '1999-12-31'
$year = substr($date,0,4);
$month = substr($date,5,2);
$day = substr($date,8,2);
$newdate = $day.'-'.$month.'-'.$year;
?>
So, $date is the start date where each month and day must be two characters, eg 02, 11 etc. and puts the formatted date in $newdate.
Try this.
$now = Date('Y-m-d');
And this
$then = Date('m-d-Y',$now);
to switch it back.
Rob