Jump to content

[SOLVED] Its NOT 1st January 1970!!


HughbertD

Recommended Posts

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

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>");

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

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.