Jump to content

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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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