PHP date question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

PHP date question

Post 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 :(
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
smudge
Forum Contributor
Posts: 151
Joined: Sun May 20, 2007 12:13 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The FROM_UNIXTIME() function in MySQL may be of interest.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Code: Select all

SELECT
   *
FROM
  `yourTable`
WHERE
  `dateField` BETWEEN 1180677600 AND 1183269599
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Post Reply