Jump to content

[SOLVED] simple time and date conversion help please!


icklechurch

Recommended Posts

Hello,

 

I'm doing something really daft with a time conversion. For example, I have the following URL:

 

www.url.com/orders.php?m=03&y=09

 

I want to then output in the php code 'March 2009' on the webpage. Similarly for url www.url.com/orders.php?m=04&y=09, I want 'April 2009' in the page, and so on.

 

At the moment I have:

 

<? echo date('F Y', mktime(0, 0, 0, 0, $_GET['m'], $_GET['y']));

?>

 

but no joy - please help!

 

 

Link to comment
Share on other sites

That code fixes the issue where the month and day were transposed, but there is still another problem. By specifying a "Day" of 0 (zero) you will get incorrect results (i.e. the previous month) since it interprets that as the last day of the previous month. Need to set the day to 1.

 

<?php
    echo date('F Y', mktime(0, 0, 0, $_GET['m'], 1, $_GET['y']));
?>

 

However, after realizing that problem I found that you could also use negative numbers for the day. So, -1 would the the second to last day of the previous month. That's an interesting feature. Not sure how it may be used, but using zero to specifiy the last day of the month will certainly come in handy.

Link to comment
Share on other sites

That code fixes the issue where the month and day were transposed, but there is still another problem. By specifying a "Day" of 0 (zero) you will get incorrect results (i.e. the previous month) since it interprets that as the last day of the previous month. Need to set the day to 1.

 

<?php
    echo date('F Y', mktime(0, 0, 0, $_GET['m'], 1, $_GET['y']));
?>

 

However, after realizing that problem I found that you could also use negative numbers for the day. So, -1 would the the second to last day of the previous month. That's an interesting feature. Not sure how it may be used, but using zero to specifiy the last day of the month will certainly come in handy.

 

I jsut noticed that as well after checking out the manual following the discovery of my mistake ;)

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.