Jump to content


Photo

Couple More Date Questions?


  • Please log in to reply
2 replies to this topic

#1 barkster

barkster
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 29 June 2006 - 03:55 PM

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.

$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);

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.



#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 29 June 2006 - 04:27 PM

[!--quoteo(post=389313:date=Jun 29 2006, 11:55 AM:name=barkster)--][div class=\'quotetop\']QUOTE(barkster @ Jun 29 2006, 11:55 AM) View Post[/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.

$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);

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:
echo date('Y-m-d H:m:s', strtotime("+ 15 days"));

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:
$mysqlformatteddate = "2006-06-29 12:27:05";
echo date('Y-m-d H:m:s', strtotime($mysqlformatteddate));

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 barkster

barkster
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 29 June 2006 - 04:49 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users