Jump to content


Photo

Pulling out part of Unix Timestamp


  • Please log in to reply
2 replies to this topic

#1 WendyLady

WendyLady
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 24 September 2006 - 07:45 PM

Hi all -- I hope you are having a great weekend.

If I have dates stored in a unix timestamp, is it possible to do a MySQL query that pulls all dates from a certain month?  Do I have to pull all the dates first & then specify the ones I want (seems resource-intensive)?

Thanks so much!


Wendy

#2 obsidian

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

Posted 24 September 2006 - 07:49 PM

i would just come up with two variables (one for the first day of the month and one for the last), and then you could query for all records beween those timestamps:
<?php
list($year, $month, $day) = explode('-', date('Y-m-d'));
$first = mktime(0,0,0,$month,1,$year);
$last = mktime(0,0,0,$month,date('t'),$year);
$sql = mysql_query("SELECT * FROM table WHERE dateCol >= $first AND dateCol <= $last");
?>

hope that 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 WendyLady

WendyLady
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 24 September 2006 - 09:58 PM

Thanks so much!  I had to tweak it for my particular code, but the concept works beautifully!

Thanks again --


Wendy




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users