Jump to content

[SOLVED] Outputting date - very simple!


garry

Recommended Posts

I take it you're using a unix timestamp to get that date format, i.e. using the timestamp data type in SQL.

 

You can just use

 

<?php
$date = date('l jS F Y'); // Wednesday 12th August 2008
mysql_query("INSERT INTO `db_name` . `table_name` ( `field_name` ) VALUES ( '$date' )")
  or die('MySQL Error: ' . mysql_error());
?>

 

Check out http://uk2.php.net/manual/en/function.date.php

Ah yes, I am using a unix time stamp. I'm using the now() function to record the date and time. The only problem is that I already have a bunch of dates recorded in the database using that previously mentioned format, so how can I convert it to the new format from that?

<?php
error_reporting(E_ALL);
$sql = mysql_query("SELECT `date` FROM `db_name` . `table_name`") or die('MySQL Error: ' . mysql_error());
while($row = mysql_fetch_array($sql)) {
  $exp = explode(' ', $row['date']); // Return the date only without the time.
  $date = date('l jS F Y', $exp[0]);
  print $date;
  // OR
  mysql_query("UPDATE `db_name` . `table_name` SET `date` = '$date'");
}
?>

 

That should work, however don't hold me to it.

Hmm, the code you said didn't quite work

 

The date it is getting from the database is "2008-06-06 23:02:58"

 

When I use date('l jS F Y', $date)

 

I get the following error:

 

Notice: A non well formed numeric value encountered in /htdocs/dev/musicnews.php on line 103

 

Note - line 103 is the date() function

<?php
error_reporting(E_ALL);
$sql = mysql_query("SELECT `date` FROM `db_name` . `table_name`") or die('MySQL Error: ' . mysql_error());
while($row = mysql_fetch_array($sql)) {
   // $exp = explode(' ', $row['date']); // Return the date only without the time.
  $date = date('l jS F Y', $row['date']);
  print $date;
  // OR
  mysql_query("UPDATE `db_name` . `table_name` SET `date` = '$date'");
}
?>

 

Try that, sorry if i'm not being much help.. I'm at work so it's difficult for me to go in-depth.

Hmm, nope, still doesn't work.

 

All I'm trying to do is turn this: "2008-06-06 23:36:41", into something like this "Friday 6th June 2008"

 

I tried using that $date = date('l jS F Y', $row['date']); function but it just returns the same error:

 

Notice: A non well formed numeric value encountered in /htdocs/dev/musicnews.php on line 103

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.