Jump to content

Couple More Date Questions?


barkster

Recommended Posts

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:15
2006-07-14 11:07:15

Also, 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.

Link to comment
https://forums.phpfreaks.com/topic/13220-couple-more-date-questions/
Share on other sites

[!--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:15
2006-07-14 11:07:15

Also, 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

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.