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

How to do less than equal to for date in sqlite

When I try to run the below query I get no result even though the date time is same as that in the table. The BillDateTime column is of TEXT Data type SELECT * FROM BillingTransaction WHERE BillDateTime <= datetime('2021-09-19…
kumar
  • 8,207
  • 20
  • 85
  • 176
-1
votes
1 answer

Can we use arithmetic operators (+, -. *, or /) on date functions in mysql?

I am learning mysql and I am stuck in the following question. Can we use arithmetic operators (+, -. *, or /) on date functions in mysql? Can someone help me out with it?
Anshul Gupta
  • 265
  • 2
  • 12
-1
votes
1 answer

How can i change column with dd--MON-yyyy format to dd-mm-yyyy

I have column name PERIODE with dd-MON-yyyy format and I want to change it to dd-mm-yyyy format, already tried some function but the format didn't changed
-1
votes
1 answer

Taking month and year from column and showing last date of the month and year

So i have 2 column Year and Month and I want to take the month and the year to show in the new column and showing the last date of the month Example : Year column = 2019, 2020, 2021 Month Column = Jan, Feb, Mar i want the result : 31-01-2019,…
Michael
  • 1
  • 5
-1
votes
2 answers

Convert string to datetime - SQL

I have a string parsed from XML which represents datetime. String format is: '20200915114000' - (YYYYMMDDhhmmss) Is there a function in SQL Server to convert or parse this string to datetime or should I split string manually and concatenate it into…
SZenko
  • 9
  • 3
-1
votes
2 answers

SQL query: A view which gathers from today last month and 2 month in advance

I'm amending a current query which I run on a fairly regular basis for a membership team looking at recent expiries. The clause in that query is: and date_expiry between '2019-11-01' and '2019-12-31' The dates are expanded to cover a 2 month…
Punter
  • 31
  • 4
-1
votes
2 answers

Bigquery : Dateadd and datediff

I am bit stuck at the below: I am able to get the subpart of date_diff but not together. any help is appreciated. SQL Server : SELECT (DATEADD(DD, DATEDIFF(dd, 0, GETDATE()), 0)) Big Query : SELECT DATETIME_ADD(CURRENT_DATETIME(),…
Aced
  • 89
  • 1
  • 2
  • 8
-1
votes
1 answer

Date Functions in MySQL

Looking for some help regarding mysql date functions. I am looking to show data for a time period of today to 8 days ago (I have been using this line of code in mysql WHERE TIME > CURDATE() - INTERVAL 8 DAY ) ) as well as the above time period but…
KCh
  • 1
-1
votes
1 answer

How to write a SQL getdate function to conditionally use 1 of a few possible end dates

I work in Mortgage. Once an Underwriter receives a file (marked as "submitted to Underwriting"), that Underwriter can either approve, approve with conditions, or suspend that file. I am trying to find the number of days that it takes the Underwriter…
-1
votes
1 answer

Get Birthday data date wise

I have a dob(DATE) field in table which stores birth dates of users. now i have query to get users who have birth date in this month is as follow SELECT * FROM register WHERE MONTH(dob) = MONTH(NOW()) Which returns me users who have birthday on…
user9341437
-1
votes
5 answers

SQL date functions

create table sales ( sdate DATE, samount varchar2(10) ); insert into sales values('1-FEB-2016',25000); insert into sales values('2-FEB-2016',45000); insert into sales values('3-FEB-2016',25000); insert into sales…
-1
votes
1 answer

SQL Library exercises (Microsoft Access)

I almost finished all exercises, but somehow I can't solve this one. The question is: Make a list of books by title and author, where each book indicates how often it is borrowed after September 1, 2014 I'm using Microsoft ACCESS and this is…
Zindzi
  • 41
  • 1
  • 6
-1
votes
1 answer

Mysql ADDDATE() or DATE_ADD() with table columns?

How do I do something like the following SELECT ADDDATE(t_invoice.last_bill_date, INTERVAL t_invoice.interval t_invoice.interval_unit) FROM t_invoice ...where the column t_invoice.last_bill_date is a date, t_invoice.interval is an integer and…
John
  • 32,403
  • 80
  • 251
  • 422
-1
votes
1 answer

PHP Prepared statements with DATE_FORMAT and AS

This command works: SELECT `username`, DATE_FORMAT( date_register , '%d %M %Y' ) AS 'date' FROM `client` WHERE email = 'ali@abu.com' LIMIT 1 but I need to do prepared statements: SELECT `username`, DATE_FORMAT( date_register , '%d %M %Y' ) AS…
sg552
  • 1,521
  • 6
  • 32
  • 59
-1
votes
1 answer

I Need to count records in next 30 days from start_date?

I am trying to find # of records in next 30 days from start date for each record I have a table: Patid Start_date 1234 1/1/2015 1234 1/10/2015 1234 1/30/2015 1234 2/19/2015 1234 …
1 2 3
18
19