Jump to content

Setting a variable to '02' for February, '03' for march etc...


Recommended Posts

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

 

  • 2 weeks later...

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!

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.

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.