How to convert current time - 10 minutes to XMLGregorianCalendar in the format MM/dd/yyyy HH:mm:ss to a Webservice to fetch records from MDM based on the modified time?
Related
I need to know a difference between start time and end time. Both are DATETIME fields, I tried to use "-" and DATADIFF.
I already tried using DATADIFF and simple subtraction converting the field to just time.
(to_date(Fim_Hora,'HH24:MI') - to_date(Inicio_Hora,'HH24:MI')) AS Diferenca
DATADIFF(MIN,Fim_Hora,Inicio_Hora)
I need to know the time in minutes for use as parameters.
Oracle does not have a time data type. Usually, subtraction works well enough:
select (end_time - start_time) as diff
You may need to convert to a string if you want it formatted in a particular way.
In Oracle, you can directly substract dates, it returns the difference between the dates in days. To get the difference in minutes, you can multiply the result by 24 (hours per days) and 60 (minutes per hour):
(Fim_Hora - Inicio_Hora) * 24 * 60 diff_minutes
This assumes that both Fim_Hora and Inicio_Hora are of datatype DATE.
I have a column eventtime that only stores the time of day as string. Eg:
0445AM - means 04:45 AM. I am using the below query to convert to UNIX timestamp.
select unix_timestamp(eventtime,'hhmmaa'),eventtime from data_raw limit 10;
This seems to work fine for test data. I always thought unixtimestamp is a combination of date and time while here I only have the time. My question is what date does it consider while executing the above function? The timestamps seem to be quite small.
Unix timestamp is the bigint number of seconds from Unix epoch (1970-01-01 00:00:00 UTC). The unix time stamp is a way to track time as a running total of seconds.
select unix_timestamp('0445AM','hhmmaa') as unixtimestamp
Returns
17100
And this is exactly 4hrs, 45min converted to seconds.
select 4*60*60 + 45*60
returns 17100
And to convert it back use from_unixtime function
select from_unixtime (17100,'hhmmaa')
returns:
0445AM
If you convert using format including date, you will see it assumes the date is 1970-01-01
select from_unixtime (17100,'yyyy-MM-dd hhmmaa')
returns:
1970-01-01 0445AM
See Hive functions dosc here.
Also there is very useful site about Unix timestamp
SQL to subtract 30 mins from current time and output time should be military format 153010 only time part
In Oracle you can do this with:
SELECT TO_CHAR(SYSDATE - 1 / 24 / 2, 'HH24MISS') FROM DUAL
Adding 1 to a date would increase by a date, 1/24 by an hour, and 1/24/2 by 30 min.
Please note that SYSDATE will give you the time of the server which would normally by UTC. If you want the local time you have to CURRENT_DATE.
I want to switch format from hh:mm:ss to seconds into day. So I want to input a 24-hour time and have it return an integer seconds into day.
Thanks in advance!
Use the TIMEVALUE formula to convert your time into a portion of a day (0-1), then multiply by hours, minutes, and seconds. Then to get a whole number, ROUND it.
=ROUND(TIMEVALUE(<yourtimehere>) * 24 * 60 * 60)
I have a table with two columns of GMT time in seconds, and offset in minutes like this:
SELECT TOP 1 StartTime, OffSet FROM MyTable;
1247242537 -420 -- as example
What SQL function I can use to convert it to a datetime in yyyy-MM-dd hh:mm:ss as TimeStamp? The SQL I am using is SQL Server 2005.
This should do it, assuming you Epoch date is 1/1/1970 (usually for GMT seconds, but you will need to confirm)
select dateAdd(ss,1247242537+(-420*60),'1/1/1970')
== > 2009-07-10 09:15:37.000
For you code, use
select DATEADD(ss,StartTime+(Offset*60),'1/1/1970') as TheTime FROM myTable
Be sure you find some test cases to make sure the Epoch date is as expected. Basically, the GMT time is number of seconds past 1/1/1970 12:00am, so DateAdd handles that part. The offset is the number of minutes different from GMT, so multiply that by 60 to get seconds and adjust your value to DateAdd accordingly