Jump to content

[SOLVED] mysql date format to strotime function works in php5, not in php4


vynsane

Recommended Posts

i'm trying to create a list of distinct months where there are archived entries to a blog. it works on my localhost under php5, but it doesn't under php4 because the strtotime function won't understand that mysql is pulling a date in a different format. here is the sql statement:

 

SELECT DISTINCT DATE_FORMAT(submitDate,'%Y-%m') AS date FROM table WHERE archived = 'y' ORDER BY date DESC

 

and the function that i'm tring to use to turn that into a different format

 

function monthYear($submitDate) {
$formattedDate = date("F Y", strtotime($submitDate));
return "$formattedDate";
}

 

in php5, i get a list that consists of

 

September 2007

August 2007

 

(which is correct, i only have two months with archived entries)

 

but in php4 i get

 

December 1969

December 1969

 

the reason why i'm using the date_format is because i need to transform it into two different forms - the kind above, and also into 09-2007 and 08-2007 for the actual url in the link. basically two functions turn the date_format version into this link:

 

<a href="/archive:09-2007/">September 2007</a>

 

how can i pull only a distinct MONTH and YEAR (don't want distinct dates, because i'll get a row for each DAY) and then turn that into the two desired formats in php4? i've tried tacking on a "-01" to the date to fool php4 into thinking that it's a full legitimate date, but that only freaks it out more. perhaps i'm just not adding it correctly...

Link to comment
Share on other sites

right, i understand why it's happening, i need to get around the "pickiness" or "limitations" (depending on how you see it) of php4's strtotime function and figure out a way to get to what i need.

 

i've tried variations of adding "-01" to the end of my date variable to try to fill it out into a full date, but to no avail. like this:

 

$row['date']-01 = $fauxDate;

"".$row['date']."-01" = $fauxDate;

 

and so on, but it's not working...

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.