Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.