I am working on booking website. I've booking table with date_created and time_created field. I am storing todays date as date_created and current time as time_created. I want to list the booking after 15 minutes of time_created in admin panel. How this can be done?
I'd tried this query.
SELECT *
FROM tbl_booking
WHERE (date_created = '$todaysdt'
AND time_created >= '$timenow')
OR (date_created < '$todaysdt')
ORDER BY booking_id DESC
but this not working. Any help will be appreciated. Thanks in advance.
Give this a shot:
select *
from tbl_booking
where STR_TO_DATE(concat_ws(date_created," ",time_created),"%Y-%m-%d %H:%i") < DATE_SUB(NOW(), INTERVAL 15 MINUTE)
order by booking_id desc
i think may be you need this: UPDATED
select * from tbl_booking where (date_created = CURDATE() AND time_created <= time(DATE_SUB(NOW(), INTERVAL 15 MINUTE))) OR (date_created < CURDATE()) order by booking_id desc
Related
I am working on an event management project, I need to get upcoming event from database, can anyone help me ?
I am using
SELECT *FROM EVENTS WHERE DATE_ADD(event_date, INTERVAL YEAR(CURDATE())-YEAR(event_date) YEAR)
BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 7 DAY) LIMIT 1;
But it gives me the event upcoming within 7 days only.
I should not want to provide days.
I want to get first upcoming event , doesn't matter after or within how many days it is coming.
thank you !
Isn't this a simple where clause comparing with current date
SELECT *
FROM EVENTS
WHERE event_date > CURDATE()
ORDER BY event_date
LIMIT 1;
Wouldn't this work?
SELECT * FROM EVENTS WHERE event_date > CURDATE() ORDER BY event_date ASC LIMIT 1;
try
If column type datetime you can use CURDATE()(mysql function) or date()(php function)
"SELECT *FROM EVENTS WHERE event_date > '".date('Y-m-d H:i:s')."' ORDER BY event_date limit 1"
or
"SELECT *FROM EVENTS WHERE event_date > CURDATE() ORDER BY event_date limit 1"
If column type date
"SELECT *FROM EVENTS WHERE event_date > '".date('Y-m-d')."' ORDER BY event_date limit 1"
try below it works perfectly fine
select * from table where start_time between NOW() AND DATE_ADD(NOW(), INTERVAL 7 DAY)
you can use like this to get next 7 days data or in case you want last 7 days then instead of DATE_ADD USE DATE_SUB It will work or you can use like
start_time between NOW() AND DATE_ADD(NOW(), INTERVAL 1 WEEK)
this also works. to know more check this ref https://dev.mysql.com/doc/en/date-and-time-functions.html
thank you everyone,
I got the answer:
SELECT * FROM EVENTS
WHERE event_date > CURDATE()
ORDER BY event_date ASC LIMIT 1;
I have this query
SELECT * FROM content
WHERE topic='$rw09[id]' AND active='1' AND date < DATE_SUB(CURDATE(), INTERVAL 1 WEEK)
ORDER BY cpc DESC, id DESC
LIMIT 4
The key part of my query is date < DATE_SUB(CURDATE(), INTERVAL 1 WEEK). It returns me entries older than a week. What i want it to return me is entries NOT older than 1 week. How can i modify it to return me desired result?
Thank you.
Have you tried with
SELECT * FROM content
WHERE topic='$rw09[id]' AND active='1' AND date > DATE_SUB(CURDATE(), INTERVAL 1 WEEK)
ORDER BY cpc DESC, id DESC
LIMIT 4
?
I am in problem in mysql database data retrieving. I have to get latest data inserted within a week or latest 7 days. I just know get data of specific date, but no within a span of days.
Please anyone help me. I am new in mysql.
You are looking for INTERVAL. For example, this will find all users whose created_time is in last 7 days and you have field created_time to tracked date of creation of record
SELECT * from users where created_time > (NOW()-INTERVAL 7 DAY)
You can do it using below query.
SELECT *
FROM `table`
WHERE `date` BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND
CURDATE()
OR
SELECT * FROM `table` WHERE `date` >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
OR
SELECT * FROM table WHERE DATEDIFF(NOW(),dateField) < 7
we can use DATE_SUB Mysql default function
select * from yourtable where date_of_insertion >= DATE_SUB(NOW(),INTERVAL 7 DAY)
<?php
$date = date("your_date_format", strtotime(- 7 days));
$result = mysqli_query($link, "SELECT * FROM table WHERE `date` > '$date'");
?>
Simple as that.
try :
select * from tablename where add_time >= now() - interval 7 day
I have the following query returning all rows from my table:
$query="SELECT * FROM $tbl_name ORDER BY job_id DESC";
I'd like to limit those results by entries less than 60 days old. I record the date an entry was made to the database using:
$dt=date('d M Y');
And this is stored in a column called 'date'.
Can someone help me to modify my query?
Thanks
Dan
If date is stored like a varchar in database, your query should be:
SELECT *
FROM $tbl_name
WHERE TO_DATE(date, 'dd MON yyyy') >= DATE_SUB(CURDATE(), INTERVAL 60 DAY)
ORDER BY job_id DESC
if date is stored like a date, use:
SELECT *
FROM $tbl_name
WHERE date >= DATE_SUB(CURDATE(), INTERVAL 60 DAY)
ORDER BY job_id DESC
$query="SELECT * FROM $tbl_name WHERE DATEDIFF(CURDATE(), STR_TO_DATE(date,'%d %M %Y')) <60 ORDER BY job_id DESC"
SELECT * FROM $tbl_name FROM_UNIXTIME(date) >= DATE_SUB(CURDATE(), INTERVAL 60 DAY) ORDER BY job_id DESC
Try this (untested)
SELECT * FROM $tbl_name WHERE date >= DATE_SUB(CURDATE(), INTERVAL 60 DAY) ORDER BY job_id DESC
You can use as
select b.mobile_number, max(b.bill_number), max(b.created_on), c.name from MasterBill as b, MasterCustomer as c WHERE b.created_on < NOW() - INTERVAL 60 DAY and b.mobile_number = c.mobile_number group by mobile_number;
consider mobile number is key binding data with customer master and billing.
Im having a little trouble constructing a query.
I have a table with 3 columns.
id - day - pageviews
What i basically want to do is get 8 id's from the table where the pageviews are the highest from the last 60 days.
The day column is a datetime mysql type.
Any help would be great, im having a little trouble figuring this one out.
Cheers,
Almost the same as TuteC posted, but you'll need a group by to get what you need...
SELECT id, SUM(pageviews) totalViews
FROM table
WHERE DATE_SUB(CURDATE(), INTERVAL 60 DAY) <= day
GROUP BY id
ORDER BY totalViews DESC
LIMIT 8
Do something like this:
SELECT id FROM table_name
WHERE DATE_SUB(CURDATE(),INTERVAL 60 DAY) <= day
ORDER BY pageviews DESC
LIMIT 8;
$sixtyDaysAgo = date('Y-m-d',strtotime('-60 days'));
$sql = "SELECT id
FROM table_name
WHERE day >= '$sixtyDaysAgo 00:00:00'
ORDER BY pageviews DESC
LIMIT 8";
If each row is a number of pageviews for that day, and you're looking for the highest total sum of 60 days' worth, then you'll need to total them all and then grab the top 8 from among those totals, like so:
$sql = "SELECT id
FROM (
SELECT id, SUM(pageviews) AS total_pageviews
FROM table_name
WHERE day >= '$sixtyDaysAgo 00:00:00'
GROUP BY id
) AS subselect
ORDER BY total_pageviews DESC
LIMIT 8";