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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Serialize Question

Status
Not open for further replies.

lyric0n

Technical User
Dec 28, 2005
74
Hello,

I have an application that dumps a date into a MySQL table with object type of text. It is dumping a date into the table, but it doesn't store it as a date, I believe it is running it through a serialize function, then putting it in there. So a date of 6/10/2007 becomes a:3:{s:5:"month";s:1:"6";s:3:"day";s:1:"10";s:4:"year";s:4:"2007";}.

How would I convert the the string back into a date? I've tried using the unserialize function, but am having all sorts of difficulties. Any suggestions?

Thanks,
Chris

 
Code:
function getDate($string){
 $datearray = unserialize($string);
 $date = $datearray['year'] .'-'. $datearray['month'] . '-' . $datearray['day'];
 return $date;
}

this will return a date in the form yyyy-mm-dd

you can also use functions like strtotime() to return a unix timestamp and date() will format the timestamp as you might want.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top