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!

 

 

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.

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 ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.