ukweb Posted May 4, 2010 Share Posted May 4, 2010 This may be a repost so excuse me if it is, I'm not sure if I submitted the post or not... Basically I've written a program which generates the RSS feed for the work's web site. The database returns an item's post date as 'yyyy-mm-dd' hh:mm:ss'. What I want to do is say, set a variable as just the month in 2 digit numeric form based on a date. I have tried the following to no avail... // Attempt 1 $item_post_month = date('m', $row_rss_news['date']); // This didn't work! // Attempt 2 $item_post_month = date('m', mktime(0, 0, 0, $row_rss_news['date'], 0, )); // Didn't work either! help! Muchos Gratitudos if anyone can help me out on this one! Ste Quote Link to comment https://forums.phpfreaks.com/topic/200694-setting-a-variable-to-02-for-february-03-for-march-etc/ Share on other sites More sharing options...
Pikachu2000 Posted May 4, 2010 Share Posted May 4, 2010 Probably simpler to select it as a month value in the query: SELECT DATE_FORMAT(field, '%m') AS month Quote Link to comment https://forums.phpfreaks.com/topic/200694-setting-a-variable-to-02-for-february-03-for-march-etc/#findComment-1053159 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2010 Share Posted May 4, 2010 Read the manual - date It's second (optional) parameter is a timestamp, not a date format of "yyyy-mm-dd". That's why it didn't work. You need to convert it into a timestamp if you plan to do it that way. Quote Link to comment https://forums.phpfreaks.com/topic/200694-setting-a-variable-to-02-for-february-03-for-march-etc/#findComment-1053162 Share on other sites More sharing options...
ukweb Posted May 17, 2010 Author Share Posted May 17, 2010 Read the manual - date It's second (optional) parameter is a timestamp, not a date format of "yyyy-mm-dd". That's why it didn't work. You need to convert it into a timestamp if you plan to do it that way. The problem I'm having is that the original designer made the admin so it saves the date in the British format and not the american, and thats where I'm having issues (ie, yyyy-mm-dd and not yyyy-dd-mm) I have spent soo much time on this and still getting no-where! Quote Link to comment https://forums.phpfreaks.com/topic/200694-setting-a-variable-to-02-for-february-03-for-march-etc/#findComment-1059432 Share on other sites More sharing options...
PFMaBiSmAd Posted May 17, 2010 Share Posted May 17, 2010 The yyyy-mm-dd format has nothing to do with any country's localization. It is a format that allows direct greater-than/less-than comparisons and sorting. Did you look at Pikachu2000's post, because that is the fastest way to accomplish this (using php's date/strtotime is ~ 8 times slower than doing a conversion in the query.) You could also simply explode the yyyy-mm-dd value on the '-' character and use the second resulting element. Quote Link to comment https://forums.phpfreaks.com/topic/200694-setting-a-variable-to-02-for-february-03-for-march-etc/#findComment-1059451 Share on other sites More sharing options...
scampbell Posted May 17, 2010 Share Posted May 17, 2010 UNIX_TIMESTAMP(date) AS date in your SQL query will convert your datetime field to a unix timestamp. Then just use date('m', $row_rss_news['date']); Quote Link to comment https://forums.phpfreaks.com/topic/200694-setting-a-variable-to-02-for-february-03-for-march-etc/#findComment-1059568 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.