Jump to content

[SOLVED] Bizarre DATE Error


tonyawelch

Recommended Posts

I have pulled out a DATE value from my mysql database from a column titled 'event_date' with value '2009-05-25' - using the following code:

 

$get_events_query = "SELECT event_date FROM testevents WHERE YEAR(event_date) = '$year' AND MONTH(event_date) = '$month' "; 
$get_events = mysql_query($get_events_query) or die(mysql_error());
$event = mysql_fetch_array($get_events);

 

The query runs fine, no errors.

 

Now I have the date of 2009-05-25 that I want to format into 'May 25, 2009' to print.  Easy enough...you would think.  Used this code:

 

$event_date = date_3_format($event[event_date]);

function date_3_format($date)
{
$d = explode("-", $date);
$date_formatted = date('F j, Y', mktime ($d[1],$d[2],$d[0]));
return $date_formatted;
}

 

The result printed out "May 19, 2009" instead of "May 25, 2009", so I went and did some echoing out of variables to debug.

 


echo $event[event_date]; //echos out 2009-05-25 as it should

function date_3_format($date)
{
$d = explode("-", $date);
echo $d[2]; //echos out "25" as it should
$date_formatted = date('F j, Y', mktime ($d[1],$d[2],$d[0]));
echo $date_formatted;  //echos out "May 19, 2009" wtf?  How did this happen?
return $date_formatted;
}

 

I'm sure I've done something stupid somewhere but I can't even begin to imagine what it was. 

 

Thanks everyone for your help - I have found this forum to be the most helpful resource of PHP and MYSQL assistance anywhere on the net, truly.

 

 

Link to comment
Share on other sites

int mktime ([ int $hour= date("H") [, int $minute= date("i") [, int $second= date("s") [, int $month= date("n") [, int $day= date("j") [, int $year= date("Y") [, int $is_dst= -1 ]]]]]]] )

 

The parameters are hours, minutes, seconds, month, day, year. You are/were putting the month day and year into the hours, minutes, and seconds positions.

Link to comment
Share on other sites

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.