Page 1 of 1

PHP date question

Posted: Sun Jun 17, 2007 11:06 am
by thiscatis
I'm converting the date (e.g.) 2007-01-01 to '1167606000' using strtotime().
The new date is stored in a column in an mySQL database.

The problem is that I want all entries for a current month.
How do I filter these results out from my database?
For example "I want to see all the entries entered in June 2007.

I tried to get the results with a query where all results should be between 06-01 and 06-30 but no luck :(

Posted: Sun Jun 17, 2007 11:13 am
by superdezign
You don't have to use timestamps in your database. DATETIME is a lot more convenient.

I could be mistaken, but I think the traditional TIMESTAMP was turned into the same format as DATETIME in MySQL 5.

Posted: Sun Jun 17, 2007 11:14 am
by smudge
take a look at the php date() function.
Format your date using the available options so that when you retrieve the records, you can easily determine month, year, etc.
Also, I don't know much about it, but MySQL has a date type available.

Posted: Sun Jun 17, 2007 7:46 pm
by feyd
The FROM_UNIXTIME() function in MySQL may be of interest.

Posted: Mon Jun 18, 2007 9:58 am
by pickle

Code: Select all

SELECT
   *
FROM
  `yourTable`
WHERE
  `dateField` BETWEEN 1180677600 AND 1183269599

Posted: Mon Jun 18, 2007 12:52 pm
by RobertGonzalez