I need to know how to add 2 hours to the below 'Completed' timestamp.
Here is the Select statement
Select Tsk.task_id,Tsk.org_id,Tsk.completed,Tsk.assgn_acct_id,name
FROM tdstelecom.tasks As Tsk
WHERE Tsk.task_id = '11094836'
AND DATE(Tsk.completed) < CURDATE() AND DATE(Tsk.completed) >= DATE_SUB(CURDATE
(),INTERVAL 180 DAY)
Here are the results: 2012-08-22 14:18:14
Desired results: 2012-08-22 16:18:14
Your tag says mySQL, use the subtime(exp1,exp2) function SUBTIME(Tsk.completed, '02:00:00.000000') in your select should do the trick.
select Tsk.completed+interval 2 hour,Tsk.assgn_acct_id,name
FROM tdstelecom.tasks As Tsk
WHERE Tsk.task_id = '11094836'
AND DATE(Tsk.completed) < CURDATE() AND DATE(Tsk.completed) >= DATE_SUB(CURDATE
(),INTERVAL 180 DAY)
Related
I need to select rows from mdl_logstore_standard_log, the condition is timecreated should be in between last five days 7.30 AM to 4.30PM. How can I achive the combination last 5 days and the time. This is what I have
SELECT * FROM mdl_logstore_standard_log
WHERE FROM_UNIXTIME(timecreated) >= DATE_SUB(CURDATE(), INTERVAL 5 DAY)
GROUP by userid
timecreated is in unixtimestamp
You can do this way too
SELECT
*
FROM mdl_logstore_standard_log
WHERE timecreated >= UNIX_TIMESTAMP(CURDATE() - INTERVAL 5 DAY)
AND (
(timecreated % 86400)
BETWEEN UNIX_TIMESTAMP('1970-01-01 07:30')
AND UNIX_TIMESTAMP('1970-01-01 16:30')
)
GROUP by userid
timecreated % 86400 would return the residue in seconds.
And if the residue lies between 1970-01-01 07:30 and 1970-01-01 16:30 then your condition is actually met.
Note:
Using GROUP BY without aggregate function is discouraged.
(#scaisEdge already stated that)
If you approach this way you take advantage from index on
timecreated field (if any)
PLS try this
SELECT * FROM mdl_logstore_standard_log
WHERE FROM_UNIXTIME(timecreated) >= FROM_UNIXTIME(DATE_SUB(CURDATE(), INTERVAL 5 DAY))
GROUP by userid;
You could use time
SELECT * FROM mdl_logstore_standard_log
WHERE FROM_UNIXTIME(timecreated) >= DATE_SUB(CURDATE(), INTERVAL 5 DAY)
AND time(FROM_UNIXTIME(timecreated))
between time('2016-01-01 07:30:00.0000' ) and time('2016-01-01 16:30:00.0000' )
GROUP by userid
NB you are using group by without aggregation function .. this could retrive not coherent result ..
I've been asking many question here, but it was dead end, I just want to make a simple select from date_column+3 day, I'm new to MySQL.
I've tried with this query
SELECT *
FROM pemesanan
WHERE pemesanan.`date` = DATE(DATE_ADD(date, INTERVAL 3 DAY))
but the result is empty, here's my column
date
2016-08-10
2016-08-04
2016-08-07
it must be show the 2016-08-10 data, but its not,
Can somebody enlighten me, I've been frustrated with this
If you use date right side you should use date left side
SELECT *
from pemesanan
where date(pemesanan.`date`) = DATE(DATE_ADD(NOW(), INTERVAL 3 DAY))
If you use the same date pemesanan.date you never get pemesanan.date = pemesanan.date +3
but if you want select the date older than 3 day you shuold use
SELECT *
from pemesanan
where date(pemesanan.`date`) <= DATE(DATE_sub(NOW(), INTERVAL 3 DAY))
and for delete
DELETE from pemesanan
where date(pemesanan.`date`) <= DATE(DATE_sub(NOW(), INTERVAL 3 DAY))
in your case
SELECT *
from pemesanan
where date(pemesanan.tanggal) <= DATE(DATE_sub(NOW(), INTERVAL 3 DAY))
I have been looking at this statement for ages and simply cannot find the error can you guys help?
SELECT XD.*, UhED.row_class,
(SELECT id
FROM Comment C
WHERE C.Excel_Data_Excel_Lists_id = XD.Excel_Lists_id
AND C.Excel_Data_row = XD.row
LIMIT 1
) AS has_activity
FROM User_has_Excel_Lists UhXL
JOIN Excel_Lists XL
ON XL.id = UhXL.Excel_Lists_id
JOIN Excel_Data XD
ON XD.Excel_Lists_id = XL.id
LEFT JOIN User_has_Excel_Data UhED
ON UhED.Excel_Data_Excel_Lists_id = XL.id
AND UhED.Excel_Data_row = XD.row
AND UhED.User_id = 1
WHERE UhXL.User_id = 1
AND XL.created > DATE_SUB(DATE(now()), INTERVAL 2)<-- it says that the error is here
GROUP BY XD.telephone
ORDER BY last_name ASC, first_name ASC
AND XL.created > DATE_SUB(DATE(now()), INTERVAL 2 DAY)
try this it may help you
You forgot do specify the interval unit maybe? Something like INTERVAL 2 DAY or INTERVAL 2 HOUR maybe?
You may need to specify the measure for the interval (e.g., days, months, etc.)
You can check the syntax for DATE_SUB here
if i understand your problem like follow this instructions as:
you should must mention the day, month, hour, or year in the following line:
your code:
AND XL.created > DATE_SUB(DATE(now()), INTERVAL 2)
change code: DAY
AND XL.created > DATE_SUB(DATE(now()), INTERVAL 2 DAY)
if you are using the DATE(tablename) in your table you getting error like:
WRONG CODE (sample)(http://sqlfiddle.com/#!2/5b7e2/7):check the code no:5
SELECT id,DATE_SUB(DAT(NOW()), INTERVAL 2 DAY)
FROM supportContacts;
RIGHT CODE:
SELECT id,DATE_SUB(DATE(NOW()), INTERVAL 2 DAY)
FROM supportContacts;
REFER THIS LINK: http://sqlfiddle.com/#!2/5b7e2/7
First of all let me give you guys the SQLFiddle: http://sqlfiddle.com/#!2/1d8bd/11
I've been working on this for a while and am facing some programmers (and writers) block.
This is a sample pseudo code of what I am trying to accomplish in MySQL:
Return all rows WHERE {
(`to_user_id` = '27' AND `to_delete` >= SUBDATE(NOW(), INTERVAL 720 HOUR) )
AND
(`from_user_id` = '27' AND `from_delete` >= SUBDATE(NOW(), INTERVAL 720 HOUR) )
}
Are you looking for this (using OR instead of AND between groups of conditions)?
SELECT *
FROM messages
WHERE (to_user_id = 27 AND `to_delete` >= NOW() - INTERVAL 720 HOUR)
OR (from_user_id = 27 AND `from_delete` >= NOW() - INTERVAL 720 HOUR)
Here is SQLFiddle demo
One issue you're having is your to_delete and from_delete fields are both NULL in your Fiddle example. Therefore, they can never meet your WHERE criteria.
That apart, no need for parentheses if all of your operators are AND. Perhaps you're looking for OR instead?
I have this SQL:
$sql="SELECT *
FROM table
WHERE expiresdate >= Date(Now())
AND expiresdate <= Date_add(Date(Now()), INTERVAL 10 day)
ORDER BY expiresdate ASC";
it should basically show all rows in the database that are going to expire within 10 days time however, lets say the expiredate was 2013-03-06 - this row will not display on any day after the expiredate
does anyone have any ideas?
This should be what you need:
SELECT
*
FROM
`table`
WHERE
expiresdate <= CURDATE() + INTERVAL 10 DAY
ORDER BY
expiresdate ASC