barkster Posted June 29, 2006 Share Posted June 29, 2006 why is my minute always off by one here? I'm trying to add 15 days to a date. Even if I do $t+(60*60*24*15-60) the minute never changes.[code]$t = time();$timestamp_future = $t + (60*60*24*15);$t = date("Y-m-d H:m:s",$t);$timestamp_future = date("Y-m-d H:m:s",$timestamp_future);echo('<br>'.$t.'<br>'.$timestamp_future);[/code]Returns:2006-06-29 11:06:152006-07-14 11:07:15Also, since mysql requires date in "Y-m-d H:m:s" how can I go from format from "Y-m-d H:m:s" to "M-d-y g:i:s" I thought I could do date("M-d-y g:i:s",$mysqlformatteddate) but of course it doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/13220-couple-more-date-questions/ Share on other sites More sharing options...
obsidian Posted June 29, 2006 Share Posted June 29, 2006 [!--quoteo(post=389313:date=Jun 29 2006, 11:55 AM:name=barkster)--][div class=\'quotetop\']QUOTE(barkster @ Jun 29 2006, 11:55 AM) [snapback]389313[/snapback][/div][div class=\'quotemain\'][!--quotec--]why is my minute always off by one here? I'm trying to add 15 days to a date. Even if I do $t+(60*60*24*15-60) the minute never changes.[code]$t = time();$timestamp_future = $t + (60*60*24*15);$t = date("Y-m-d H:m:s",$t);$timestamp_future = date("Y-m-d H:m:s",$timestamp_future);echo('<br>'.$t.'<br>'.$timestamp_future);[/code]Returns:2006-06-29 11:06:152006-07-14 11:07:15Also, since mysql requires date in "Y-m-d H:m:s" how can I go from format from "Y-m-d H:m:s" to "M-d-y g:i:s" I thought I could do date("M-d-y g:i:s",$mysqlformatteddate) but of course it doesn't work.[/quote]first of all, if you're simply trying to get 15 days in the future, why don't you just do this:[code]echo date('Y-m-d H:m:s', strtotime("+ 15 days"));[/code]the second question can be answered by the fact that date() takes a UNIX timestamp as the second argument, not a SQL datestamp, so you'd need to do this as well:[code]$mysqlformatteddate = "2006-06-29 12:27:05";echo date('Y-m-d H:m:s', strtotime($mysqlformatteddate));[/code]hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/13220-couple-more-date-questions/#findComment-50892 Share on other sites More sharing options...
barkster Posted June 29, 2006 Author Share Posted June 29, 2006 Wow, nobody ever caught this one... mine may have worked from the beggining if I wan't using H:(m):s I was using month instead of minutes.....Thanks for all the help in clearing up my formatting issues Quote Link to comment https://forums.phpfreaks.com/topic/13220-couple-more-date-questions/#findComment-50903 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.