Select * if today?
Moderator: General Moderators
Select * if today?
Hello,
Can someone assist me in a SQL statement. Trying to select * from table where `UnixTime` is within 24 hours?
Thankyou,
Rob.
Can someone assist me in a SQL statement. Trying to select * from table where `UnixTime` is within 24 hours?
Thankyou,
Rob.
Thanks for the reply.
The unix time is the unix timestamp that is in the "myDate" column. So it will be something like:
select * from myTable where `myDate` within 24 hours. And by 24 hours, I mean from the start of the day. So if it's Friday night, I want all the records since friday morning at 12:00AM.
Hope this clarifies. Thanks in advance.
The unix time is the unix timestamp that is in the "myDate" column. So it will be something like:
select * from myTable where `myDate` within 24 hours. And by 24 hours, I mean from the start of the day. So if it's Friday night, I want all the records since friday morning at 12:00AM.
Hope this clarifies. Thanks in advance.
-
jamiel
- Forum Contributor
- Posts: 276
- Joined: Wed Feb 22, 2006 5:17 am
- Location: London, United Kingdom
Code: Select all
SELECT * FROM myTable WHERE FROM_UNIXTIME(myDate) > CURDATE();feyd:
I took your advice this is as close as I can get, but it still returns nothing:
Can you see a problem?
jamiel: no luck either, sorry.
I took your advice this is as close as I can get, but it still returns nothing:
Code: Select all
$time = time();
$start_time = mktime(0, 0, 0, date('m', $time),date('d', $time),date('Y', $time));
$queryToday = "SELECT * FROM `Statistics` WHERE `ID` = '$ID' BETWEEN $start_time AND $time";
//get all times from early this morning to nowCan you see a problem?
jamiel: no luck either, sorry.
If you just want to select all from today, then format FROM_UNIXTIME() to = CURDATE();!
Like so...
pif!
Like so...
Code: Select all
SELECT * FROM my_table WHERE FROM_UNIXTIME(myDate, '%Y-%m-%d') = CURDATE();pif!
php running on its own
ok i see you are talking about something related to my question, but it is a little bit different.
Is it posible a php script to run on its own, not triggered by a user, but automatically. For example I want my php script to run every monday at 12:00. Is it posible and how is it posible?
According to me this is not possible, but one told me I'm wrong. So I'm getting confused. Thanx for the help in advance.
Is it posible a php script to run on its own, not triggered by a user, but automatically. For example I want my php script to run every monday at 12:00. Is it posible and how is it posible?
According to me this is not possible, but one told me I'm wrong. So I'm getting confused. Thanx for the help in advance.
Re: php running on its own
I don't see how it is related, but just try to google for cron jobs.57an wrote:ok i see you are talking about something related to my question, but it is a little bit different.
Is it posible a php script to run on its own, not triggered by a user, but automatically. For example I want my php script to run every monday at 12:00. Is it posible and how is it posible?
According to me this is not possible, but one told me I'm wrong. So I'm getting confused. Thanx for the help in advance.
It does make sense.xterra wrote:Whoa. It worked. This doesn't make sense. But it works lol.
For yesterday try:xterra wrote:If I want to find something from yesterday how come I can't just use curdate()-1?
Code: Select all
SELECT * FROM `Stat` WHERE `UID` = '$UID' AND FROM_UNIXTIME(`date`, '%Y-%m-%d') = (CURDATE() - INTERVAL 1 DAY)Thanks Oren. That was useful because I was able to put it in a for loop to get data for the last 7 days. Works well, if anyone wants to see:
Code: Select all
for ($i=0;$i<7;$i++)
{
$queryDay= "SELECT * FROM `Stat` WHERE `UID` = '$UID' AND FROM_UNIXTIME(`date`, '%Y-%m-%d') = (CURDATE() - INTERVAL $i DAY)";
$resultDay=mysql_query($queryDay);
$numDay=mysql_numrows($resultDay);
echo "$numDay";
}