Link to home
Start Free TrialLog in
Avatar of j_k
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.
Avatar of rmgalante
rmgalante

Yes.

Try this.

$now = Date('Y-m-d');

And this

$then = Date('m-d-Y',$now);

to switch it back.

Rob
Avatar of j_k

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


ASKER CERTIFIED SOLUTION
Avatar of freshmeat
freshmeat

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
     
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.