Jump to content

Wierd date() output


foreverhex

Recommended Posts

Ok so Ive have never used the date() function before untill now. I thought I had it all down (simple it seemed) but some how I getting something weird.

[code]$signupdate = date("F d Y" , $row["signupdate"]);
$lastlogin = date("F d Y" , $row["lastlogin"]);[/code]

The $row["signupdate"] and $row["lastlogin"] are from a MySQL query and it out put something like this normally: 2006-07-12 23:28:57.

But when I load the page it comes out as: December 31 1969. ???? Why, what, no! Any ideas?
Link to comment
https://forums.phpfreaks.com/topic/14626-wierd-date-output/
Share on other sites

The date() function is expecting a UNIX timestamp as the second parameter, not a string. A UNIX timestamp is the number of seconds since 1-1-1970 for the date. To get this number you can use the strtotime() function. So in your case:
[code]<?php
$signupdate = date("F d Y" , strtotime($row["signupdate"]));
$lastlogin = date("F d Y" , strtotime($row["lastlogin"]));
?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/14626-wierd-date-output/#findComment-58198
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.