Solved

How to minus 6 hours from a timestamp?

Posted on 2008-10-20
4
1,336 Views
Last Modified: 2012-05-05
Hi,

I have a need to minus 6 hours from a time stamp if the current timestamp is greater than the current time.

I have attached the script for you to see.

Not sure what I'm doing wrong here.

Any help would be much appreciated.

Regards

Ken
UPDATE SMSIN_copy
SET validDate = realdate - 6 hour
where realdate > CURRENT_TIMESTAMP()

Open in new window

0
Comment
Question by:kenuk110
  • 2
4 Comments
 
LVL 11

Expert Comment

by:miqrogroove
ID: 22764864
Timestamps are expressed in seconds, so,

UPDATE SMSIN_copy
SET validDate = realdate - (6 * 60 * 60)
where realdate > CURRENT_TIMESTAMP()
0
 
LVL 17

Accepted Solution

by:
HuyBD earned 125 total points
ID: 22764885
try this
UPDATE SMSIN_copy
SET validDate = date_add(realdate,interval -6 hour)
where realdate > CURRENT_TIMESTAMP()

Open in new window

0
 

Author Comment

by:kenuk110
ID: 22764889
Thanks for the quick response!

I ran the script but I get an odd output, below is just one of the results

realdate = 2008-10-21 12:30:43

but

validDate = 2008-10-21 10:14:43

Any ideas??

Thanks
0
 

Author Closing Comment

by:kenuk110
ID: 31508169
Brilliant, works perfectly. Cheers.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now