Jump to content

Date


scott100

Recommended Posts

Date is saved in mysql datebase.When printed from the database with this:

{$row['date']}

I get this result: 2008-12-31what i want to do is format that date so it looks neater so i need helpI tried this

$d=date('j F y', $row['date']);

but that prints out1 January 70for all my dates :) How can print my date formated?

Link to comment
Share on other sites

well, I think that is where the unix timestamp (or whatever it's called) goes from.  it looks like the date() function doesn't recognize the format you are using.

Yeah apparently they don't go together, i found this on another forum and it works, maybe it will help someone else :)
//Remove the '-' from the standar MySQL sate formatlist($Year,$Month,$Day) = split('-',$row['date']); //Create a UNIX style timestamp from the result$stampeddate = mktime(12,0,0,$Month,$Day,$Year); $realDate = date("jS F Y",$stampeddate);

Link to comment
Share on other sites

Probably break it up yourself, and either create a new date object if you want to get more info than what you already have (day of the week or month name or whatever), or just rearrange the 3 parts. $chunks = explode("-", $row['date']);list($year, $month, $day) = $chunks;$d = getdate(mktime(0, 0, 0, $month, $day, $year));Now you have an array of the things available through getdate, like month name or day name.

Link to comment
Share on other sites

Holy crap, that's almost exactly what I did.  But yeah, it's for reasons like this that I only store my dates and times in Unix timestamp format.

Nearly spot on :) How do i save them as unix timestamp format, i am using now() to timestamp everything logged in the db
Link to comment
Share on other sites

You can use mktime to convert to a timestamp, use time to get the current one, and use getdate to convert from a timestamp into an array with more info.http://www.php.net/manual/en/function.mktime.phphttp://www.php.net/manual/en/function.time.phphttp://www.php.net/manual/en/function.getdate.phpYour database fields can just be normal integers, they don't need to be long or float or anything.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...