icklechurch Posted April 16, 2009 Share Posted April 16, 2009 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! Quote Link to comment Share on other sites More sharing options...
gevans Posted April 16, 2009 Share Posted April 16, 2009 <?php //hour, minute, second, month, day, year echo date('F Y', mktime(0, 0, 0, , $_GET['m'], 0, $_GET['y'])); ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 16, 2009 Share Posted April 16, 2009 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. Quote Link to comment Share on other sites More sharing options...
icklechurch Posted April 16, 2009 Author Share Posted April 16, 2009 Bloody brilliant - thank you very much! Quote Link to comment Share on other sites More sharing options...
gevans Posted April 16, 2009 Share Posted April 16, 2009 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 Quote Link to comment 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.