Jump to content

help with a mysql query? Huh


w32

Recommended Posts

Hello guys I wondered whether you could help me with a mysql query..  :)

So...I have a field in a table, with a date int. It's a script that groups news elements by day. Then all the news for that specific day must be displayed. And I'm having trouble with that...

The int in the database field contains the info of the day, year, month etc (basically date("U") )

But I only need to get the day, to get all the news of a specific day...how could I make a query like that  ???
Link to comment
https://forums.phpfreaks.com/topic/19475-help-with-a-mysql-query-huh/
Share on other sites

If you wnat to get the day from a timestamp use
[code]<?php

$timestamp = time();

$day = date("j", $timestamp);

?>[/code]
Then use $day in your SQL query.

Note j in the date function returns the day without the leading zero eg (1 - 31)
if you wnat the leading zero use d
Life would be a lot simpler if you had stored a date yyyy-mm-dd field instead of the number of seconds since the start ot time ... the query would have been simple then.

As it is, the only route I see is to get a specific date (via form input or URL) and then process it so as to get the 'time' at 00:00 on that day and the 'time' at 23:59 on that day and then do a SELECT where yourtimefield is less than the 23:59 time AND yourtimefield is more than the 00:00 time.
[quote author=w32 link=topic=106625.msg426642#msg426642 date=1157219387]
... wanted to know if someone knew how to do it :)
[/quote]

Isn't that what I just told you?  Write a snippet of code to try.  The manual pages on the date() and time() functions tell you all you need to know.  If you run into trouble, post your code and explain the troubles you're having.

Archived

This topic is now archived and is closed to further replies.

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