Get the date with 0 as time [duplicate] - sql

This question already has answers here:
how to remove time from datetime
(10 answers)
What is the best way to truncate a date in SQL Server?
(6 answers)
Closed 8 years ago.
I'm using the following query to get the maximum days in a month as a datetime.
Select DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,'2014-01-01')+1,0))
The query result is: 2014-01-31 23:59:59.000
How can I get the following result : 2014-01-31 00:00:00.000
Thanks,

Related

Previous Workday in Where Clause [duplicate]

This question already has answers here:
How to get Previous business day in a week with that of current Business Day using sql server
(8 answers)
Select the previous business day by using SQL
(3 answers)
Closed 3 months ago.
How do I obtain the previous working date in a where clause
without doing the following and changing this manually
WHERE date = GETDATE()-1
The date column is datetime but I just need the date too.

How to calculate average time in SQL Big Query? [duplicate]

This question already has answers here:
How to calculate average time when it is used TIME format in Bigquery?
(3 answers)
SQL AVG Function with with a time format
(1 answer)
Closed 5 months ago.
I want to find out average time on SQL Big Query. I tried using the CAST function but it's not working.
For example-
Ride_length
01:01:00
00:58:00
01:14:00
00:34:00
01:03:00
00:34:00
00:40:00
01:00:00
there are 5451210 rows in ride_length column.
Date type = TIME
Please help!

SQL -5 minutes from a existing column [duplicate]

This question already has answers here:
Get records 10 min before system datetime in SQL
(4 answers)
Closed 6 years ago.
How can I substract the column "begin_execution" with 5 minutes?
The begin_execution-Datetime will filled via an SQL-Task, but i need this time -5 minutes to check the running compatibility.
Example:
SELECT * FROM queue_entry WHERE begin_execution - GETDATE()-5min AND STATUS = 'not solved'
Thats the original output:
2016-06-09 15:00:11.4070000
i need this output (-5 minutes):
2016-06-09 14:55:11.4070000
WHERE begin_execution >= DATEADD(MINUTE, -5, GETDATE())

Compare a datetime field within 2 hours [duplicate]

This question already has answers here:
SQL: Get records created in time range for specific dates
(3 answers)
Closed 8 years ago.
I have a table with the field ENTERED_ON (with both date and time value). I want to write a query that return records that have ENTERED_ON value that is past 2 hours comparing to current date time.
For example, if entered_on is 2014-05-06 11:00AM, and currently it's 2014-05-06 2:00PM, I would like to return all records that past the 2 hours when comparing to current date time.
You can write query using INTERVAL. It will looks like
SELECT * FROM Table WHERE `ENTERED_ON` > DATE_ADD(NOW(), INTERVAL -2 HOUR)

SQL last month date of given date [duplicate]

This question already has answers here:
Get the last day of the month in SQL
(22 answers)
Closed 9 years ago.
i am using sql
How to get the last day of the month for a given date
01/03/2014 should return 01/31/2014
I only need the date part.. Thanks
For SQL-SERVER, try this:
SELECT convert(varchar,(DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,'01/03/2014 ')+1,0))),101)