HughbertD Posted December 29, 2007 Share Posted December 29, 2007 Hi I am trying to display a date from a mysql database - when I attempt any formatting it displays the date jan 1st 1970 My code : $ConvertedStartDate = date("F jS, Y", $startdate); echo $ConvertedStartDate; I have read that timestamps start from this date - is it the date function that is the problem? Link to comment https://forums.phpfreaks.com/topic/83595-solved-its-not-1st-january-1970/ Share on other sites More sharing options...
Orio Posted December 29, 2007 Share Posted December 29, 2007 Jan 1st 1970 means that the timestamp is 0. So my guess is $startdate is not defined correctly, maybe a mistype somewhere? If you can't find it, post your code. Orio. Link to comment https://forums.phpfreaks.com/topic/83595-solved-its-not-1st-january-1970/#findComment-425286 Share on other sites More sharing options...
HughbertD Posted December 29, 2007 Author Share Posted December 29, 2007 I'm not sure this is the case Without any formatting the date displays correctly but in YYYY-MM-DD format. Its only the moment I use the date() function that the Jan 1st becomes a problem. Is the date() function the correct way to format a date? More comprehensive code <?php //echo ("'$_GET[id]'"); $SQL = "select * from student, placement, studentplacement where student.studentid = studentplacement.studentid and placement.companyID = studentplacement.companyID and studentplacement.studentID = '$_GET[id]'"; // echo ("$SQL\n"); $retid = mysql_query($SQL, $cid); if (!$retid) { echo( mysql_error()); } else { echo "<P><TABLE CELLPADDING=4 align=center>\n"; ?> <tr> <td align="center"><b>Company</b></td> <td align="center"><b>Start Date</b></td> <td align="center"><b>End Date</b></td> </tr> <?php while ($row = mysql_fetch_array($retid)) { $compName = $row["compName"]; $compCity = $row["compCity"]; $compCountry = $row["compCountry"]; $email = $row["email"]; $compid = $row["companyID"]; $startdate = $row["start"]; $enddate = $row["end"]; $ConvertedStartDate = date("F jS, Y", $startdate); echo ("<TR>"); echo ("<TD>$compName $compCity, $compCountry</TD>\n");?> <?php ?> <TD align=center><?php echo $ConvertedStartDate;?></TD> <?php // echo ("<TD align=center>".date("d/m/Y",$startdate"</TD>\n"); echo ("<TD align=center>$enddate</TD>\n"); echo ("<TD><A HREF=\"changeStudPlacement.php?id=$id&task=del&compid=$compid\">Delete</A></TD>"); echo ("</TR>"); } echo ("</TABLE>"); Link to comment https://forums.phpfreaks.com/topic/83595-solved-its-not-1st-january-1970/#findComment-425289 Share on other sites More sharing options...
kenrbnsn Posted December 29, 2007 Share Posted December 29, 2007 You need to use the strtotime() function to covert the date string to the UNIX time stamp that the date() function requires. <?php $ConvertedStartDate = date("F jS, Y", strtotime($startdate)); echo $ConvertedStartDate; ?> Ken Link to comment https://forums.phpfreaks.com/topic/83595-solved-its-not-1st-january-1970/#findComment-425298 Share on other sites More sharing options...
HughbertD Posted December 29, 2007 Author Share Posted December 29, 2007 Thank you Sir! I see why people say they just use timestamps to do all this date malarkey Thanks again everyone Link to comment https://forums.phpfreaks.com/topic/83595-solved-its-not-1st-january-1970/#findComment-425303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.