How to get how many hour 4AM have there been between two dates in TSQL

I need to get how many of a specific hour have occurred between two dates in TSQL. Some examples: The following would give the result = 1 declare @date1 datetime = ‘2019-10-01 00:00:00.000’; declare …

What is the purpose of the string “- 4/24” from a record that holds a date?

I have an already generated script that uses the following code: ORDER BY TO_CHAR((A.VERIFIED_DTTM – 4/24),’YYYY-MM-DD’). The output of A.VERIFIED_DTTM is a simple date eg: 09-SEP-19. I was my …

How to convert decimal to time in Oracle SQL?

In a certain table I’m querying, time is stored like this: 09:30 is stored as 9,3 14:25 is stored as 14,25 How can I, using SQL, convert 9,3 to 09:30 (hh:mm format)? So far, the only thing I could …

Why Week conversion failed in SQL Server in my case?

I am trying to convert week of the date based on my criteria. My date condition: if my @date is less than 4 AM, then @date – 1, else @date declare @dates datetime set @dates = ‘2019-01-01 03:59:59’…

datediff for row that meets my condition only once per row

I want to do a datediff between 2 dates on different rows only if the rows have a condition. my table looks like the following, with additional columns (like guid) Id | CreateDateAndTime | …

Get query result 15 second interval in Oracle

I have following query to get 15 seconds interval. However I want to show also ‘0’ values even if the result doesn’t have value. Here is the Query; select to_char(trunc(sample_time,’hh24′) + (trunc(…

Round datetime to the beginning of the current hour

I would like to round a datetime (should also return a datetime) to the beginning of the hour it’s on, so for example: 2018-09-22 11:31:42.411 -> 2018-09-22 11:00:00.000 2018-09-22 11:08:02.456 -&…

Show average difference between two time fields as MM:SS in SQL

I am using SQL Server 2008. I have several rows of start_time and end_time. I want to calculate the average difference between these two times in a MM:SS format. start_time | end_time 10:15:30 …

MySQL – Find the largest time difference between consecutive datetimes

I have a table that contains a list of datetimes. I’d like to find the longest amount of time between consecutive datetimes ie., find the largest distance between any two datetime entries that fall …

EXTRACT the date and time – (Teradata)

I am trying to extract the date and time from a field in Teradata. The field in question is: VwNIMEventFct.EVENT_GMT_TIMESTAMP Here is what the data look like: 01/02/2012 12:18:59.306000 I’d like …