Mysql query not working with IST timezone - php

I have table "bookings" in mysql and i want to fetch those record whose "bookingtime"(data type is "Datetime") more than 40 minutes ( according to IST)
My query not working with IST,
Here is my table "booking"
id name bookingtime
1 ayhd 2020-01-09 15:23:33
2 dhdye 2020-01-09 14:53:38
3 juey 2020-01-09 11:13:53
I tried with following query but not showing any result,Where i am wrong ?
SELECT * FROM booking
WHERE bookingtime < (NOW() - INTERVAL 40 MINUTE)

try this query , it will get records between now and 40 minutes ago
SELECT * FROM `booking` WHERE `bookingtime` >= (NOW() - INTERVAL 40 MINUTE) AND `bookingtime` < NOW()

Related

MySQL retrieve data for the past 24 hours when the column table is of type date NOT timestamp

I am trying to retrieve data for the passed 24 hours but I am getting nothing, but when I check on the table column (days) directly in db, I can find them. Here is my query:
select * from mytable
where
days between concat(date(date_sub(now(), interval 1 day))
between requires 2 arguments that specify the range:
select * from mytable
where days between date_sub(now(), interval 1 day) and now();
Or simply
select * from mytable
where days > date_sub(now(), interval 1 day);
You can use
select * from mytable where days > date_sub(CURDATE(),INTERVAL 1 DAY);

MySQL query to select records newer than x days

I'm sorry if this sounds like a very basic question but for some reason, today I'm really having trouble getting my head round this. I have a database table with a date_added column in the format of 2014-09-30 20:39:17 and I have a web page with filter options for users. Basically I want to use variables to select different date ranges like so:
SELECT * FROM table WHERE date_added = /* EVERYTHING POSTED TODAY */
SELECT * FROM table WHERE date_added = /* EVERYTHING POSTED WITHIN LAST 7 DAYS */
SELECT * FROM table WHERE date_added = /* EVERYTHING POSTED WITHIN LAST 30 DAYS */
What would I need to put in to get those variables to work?
You can use CURDATE() and very simple INTERVAL arithmetic.
In the following examples assume that query was executed at 2014-10-21 22:25:28:
SELECT * FROM table WHERE date_added >= CURDATE()
-- >= 2014-10-21 00:00:00
SELECT * FROM table WHERE date_added >= NOW() - INTERVAL 24 HOUR
-- >= 2014-10-20 22:25:28
SELECT * FROM table WHERE date_added >= CURDATE() - INTERVAL 7 DAY
-- >= 2014-10-14
SELECT * FROM table WHERE date_added >= CURDATE() - INTERVAL 30 DAY
-- >= 2014-09-21

3 Months previous data by given date mysql

I have fee records in my database table. I want to fetch 3 months back records of the fees in database. I am using:
SELECT * FROM fee_challans
WHERE student_id = 630
AND STATUS = 'un-paid'
AND DATE_FORMAT( fee_date, '%Y-%m-%d' ) - INTERVAL 2 MONTH
This query that I searched and found on google.
You forgot to compare your column to something...
SELECT * FROM fee_challans
WHERE student_id = 630
AND STATUS = 'un-paid'
AND fee_date >= CURDATE() - INTERVAL 3 MONTH;
And if your fee_date column is of type date, datetime or timestamp, date_format() is not necessary.

select timestamp older than

How i can select from database the items older than 12 hours?!
I using a timestamp column to store the time but I don't think i need year,month,day only hours
I have something like this but it dosen't work (no error just returning all data from table)
$sql = "SELECT *FROM Y WHERE X and time > now() - INTERVAL 12 HOUR";
Type : timestamp
You're right Salman A .Thanks
Try this :
SELECT * FROM Y WHERE X and time < (NOW() - INTERVAL 12 HOUR)
you need < rather than > as you want to select records older than 12 hours

select query for time interval in mysql and php

select query to select all records that were inserted in 15 minutes.for ex if now time is 10:00 then it shoulld fetch all record inserted from 9:45 to 10:00
Assuming you have a DATETIME column named created in your table:
SELECT id FROM tablename
WHERE ((created > DATE_SUB(NOW(), INTERVAL 15 MINUTE))
AND (created < NOW()))
select * from table WHERE datetimeField BETWEEN date_add(NOW(),INTERVAL -15 MINUTE) AND NOW();

Categories