vynsane Posted October 8, 2007 Share Posted October 8, 2007 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 https://forums.phpfreaks.com/topic/72350-solved-mysql-date-format-to-strotime-function-works-in-php5-not-in-php4/ Share on other sites More sharing options...
cooldude832 Posted October 8, 2007 Share Posted October 8, 2007 simple answer I think is the stortime in 4 is a bit pickier than in 5 so its seeing September 2007 as 092007 which returns the year 0920 the month 07, which is pre the epoch so it stores the initail epcoh Link to comment https://forums.phpfreaks.com/topic/72350-solved-mysql-date-format-to-strotime-function-works-in-php5-not-in-php4/#findComment-364851 Share on other sites More sharing options...
vynsane Posted October 8, 2007 Author Share Posted October 8, 2007 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 https://forums.phpfreaks.com/topic/72350-solved-mysql-date-format-to-strotime-function-works-in-php5-not-in-php4/#findComment-364859 Share on other sites More sharing options...
Barand Posted October 8, 2007 Share Posted October 8, 2007 perhaps SELECT DISTINCT DATE_FORMAT(date, '%M %Y') as date1, DATE_FORMAT(date, '%m-%Y') as date2... Link to comment https://forums.phpfreaks.com/topic/72350-solved-mysql-date-format-to-strotime-function-works-in-php5-not-in-php4/#findComment-364863 Share on other sites More sharing options...
vynsane Posted October 8, 2007 Author Share Posted October 8, 2007 yeah, that did it. thanks much, barand! Link to comment https://forums.phpfreaks.com/topic/72350-solved-mysql-date-format-to-strotime-function-works-in-php5-not-in-php4/#findComment-364877 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.