Adding Hours to Date and Time Fields

Hi Experts,

I need your urgent help !

I’m storing “Start Date” and “Start Time” as two different field in application. I wanted to query “Start Date” and “Start Time” from there I wanted to add 3 hours to “Start Date” and “Start Time” as to display as initial value of “End Date” and “End Time” fields.

E.g : Start Date : 01/01/2017, Start Time: 23:00 … To BE (initial value) End Date : 02/01/2017, End Time : 02:00

Thank you in Advance.

Ismath.

You have to play a bit with the select query. I assume you use mysql? Then you could use some php-like constructs like:
SELECT * FROM table WHERE date = DATE_ADD(CURDATE(), INTERVAL 8 DAY) or for minutes: SELECT ‘2008-12-31 23:59:59’ + INTERVAL 30 MINUTE;
(Or combination :wink: hope this helps.

Thank you Albert, it was working as you guided. Great Help !

below is my sample code…

sc_lookup (dt,“SELECT (DATEADD(hh,$DurationHRS,CAST(StartDate AS datetime) + CAST(StartTime AS DATETIME))) FROM Transportation.TransportRequest WHERE RecID = 1”);

Can you advise, how to enable Time Picker for the “Date and Time” Field. I could see the Time picker is only available at the “Time field” but not in Date and time field.

Many Thanks,

You could add a custom field of that type to the form and assign it’s value to the sql in the onbefore update/insert ?

Hi Albert,

I had problem using the code ref to my previous post probably because of my DB is MS SQL Server.

However, as alternatively i have used this code “{EndDateTime} = date(‘Y-m-d H:i’,strtotime("+$ToleDuration hour",strtotime($datetime)));” where it is working perfectly.

Thank you for tips using custom field as well… is solved my problem.

Many thanks,