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! Link to comment https://forums.phpfreaks.com/topic/154363-solved-simple-time-and-date-conversion-help-please/ 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'])); ?> Link to comment https://forums.phpfreaks.com/topic/154363-solved-simple-time-and-date-conversion-help-please/#findComment-811547 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. Link to comment https://forums.phpfreaks.com/topic/154363-solved-simple-time-and-date-conversion-help-please/#findComment-811556 Share on other sites More sharing options...
icklechurch Posted April 16, 2009 Author Share Posted April 16, 2009 Bloody brilliant - thank you very much! Link to comment https://forums.phpfreaks.com/topic/154363-solved-simple-time-and-date-conversion-help-please/#findComment-811567 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 Link to comment https://forums.phpfreaks.com/topic/154363-solved-simple-time-and-date-conversion-help-please/#findComment-811571 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.