Questions tagged [sql-date-functions]

The SQL-Date-Functions tag is for questions related to database SQL functions that handle date and time information.

For database data stored as date or timestamp data types, SQL has several date functions to perform various calculations. For determining the number of days between two dates, the date values can simply be subtracted.

MS SQL Server specifics

Formatting and Converting

For converting text strings into proper date/time values there are functions such as to_date('13-Dec 2008 13.05.33', 'dd-Mon YYYY hh24.mi.ss') and functions for formatting a date into a text string, such as to_char(hire_date, 'WW-YYYY') which would return the week number and year for the hire_date.

Calculations

Other functions are used for calendaring information, such as last_day(date) which returns the last day of the month for the specified date.

See Also


The tag is used for questions regarding the various types of date/time data types such as DATE and TIMESTAMP.

284 questions
-1
votes
1 answer

Include null values within a date range

Im trying to filter out the data between the date range, which also includes null values, eg: start_date = 18/01/2013 and end_date = 20/01/2013 In some data in the database the start_date is 19/01/2013 and end_date = null; I need to include this…
shockwave
  • 3,074
  • 9
  • 35
  • 60
-2
votes
1 answer

Why does subtracting NOW with DATE column give nonsense numbers?

Hello everyone, i have a problem with the subtracting a DATETIME column with todays DATETIME. One of the columns has the HireDate (Date of hiring a certain employee). I want to know how many Years they are employed. Thank you in advance! I…
samss04
  • 11
  • 1
-2
votes
1 answer

How to retrieve data for last 2 hrs from a specific Datetime

I am trying to extract last two hours records from a specific datetime. That means, I need to find out if there's any transaction occurred before 2019-11-20 18:00:00. I have 100 records against which I need to extract 2 hrs prior activities. Can I…
adey27
  • 439
  • 3
  • 19
-2
votes
2 answers

Split date range into new records in Snowflake View

I have a table that consists of start and end dates and I need to need split records into day-wise and this needs to go in a View. | PersonID | CompanyID | Start_DT | End_DT | |-----------|--------------|-------------|-----------| | A12 …
-2
votes
2 answers

Drop tables in a database which are created older than two months from current date

I need to drop multiple tables in my DB which got created more than two months from current time. My database has these sample tables: Table_A_20200101 Table_B_20200212 Table_C_20200305 Table_Exp Table_XYZ
-2
votes
3 answers

How to find data for last 20 tuesdays

I want to find data for the last 20 Tuesday. Date value 2020-03-03 01:12:15 5 2020-02-25 07:12:15 13 2020-02-24 08:12:15 1 2020-02-23 09:12:15 32 2020-02-22 10:12:15 …
ashishmishra
  • 363
  • 2
  • 14
-2
votes
2 answers

Impala Month Name Function

Can we convert month numbers to month name. I can see a function called month name https://impala.apache.org/docs/build/html/topics/impala_datetime_functions.html#datetime_functions__month But it is not working .
-2
votes
1 answer

Rounding Date with SQL

Can anyone explain why we get this output after rounding: ROUND(TO_DATE ('22-AUG-03`), 'DDD') Result: 22-AUG-03 ROUND(TO_DATE ('22-AUG-03`), 'DAY') Result: 24-AUG-03
Barry L
  • 17
-2
votes
4 answers

Need help to write a query

I need to write a query to get tenure of assignment to a specific project. I have a table of daily activities which stores data about everyone in a company and their allocation to a project in the below format. This shows employee E123's…
VnA
  • 3
  • 3
-2
votes
2 answers

Insert Date and Time only if > = Current Date

I have a field appointment_date and appointment_time and datatype is date and time respectively. The table name is appointment. What our teacher wanted was to be able to add appointment ONLY if it is greater than or equal to the current_date or…
-2
votes
4 answers

Summation of a field in specified date range

I need help with the following -- please help . How to summate a date range.?? I am a newbie in Oracle .
redsoxlost
  • 1,215
  • 5
  • 19
  • 32
-3
votes
1 answer

how to convert month date in a text column into datetime

I have a table containing two columns like this: Month_Date Year Dec 31 2018 May 01 2020 Jun 05 2021 Jan 18 2022 Jul 19 2019 I hope to combine the Month_date and year in the same row and put it in a new column as a…
-3
votes
2 answers

how to add 30 min to date values in sql so they change correctly?

there is a timepair table. It has columns : start_pair end_pair 08:30:00 09:15:00 I need to shift it by 30 min - how to do it? 8:30 becomes 9:00. update set start_pair = date(start_pair) + minute(30)
ERJAN
  • 23,696
  • 23
  • 72
  • 146
-4
votes
1 answer

Convert date into Weeks in PostgreSQL

I want to add week against dates, start day of the date should be Saturday. can anyone tell me how to do it. enter image description here I tried below code but it didn't solve my purpose select date_part('week',dates ::date ) as weekly, …
1 2 3
18
19