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
0
votes
2 answers

how to get the last three months of last year using mysql?

How would I go about retrieving records from the last three months of the previous year? I was thinking it would be: Date_add(curdate() , interval '-1 2' year_month)
0
votes
3 answers

SQL Database Date Ranges

I have a flat table which holds status updates. These updates are stored in the following format: AgreementID | StatusID | StatusDate Source Data: AgreementID StatusID StatusDate 109 1 14/01/2013 15:00:33 109 2 …
Richard Gale
  • 1,816
  • 5
  • 28
  • 45
0
votes
2 answers

How to compare date staying in hotel is greater than a certain numner

I am trying to compute all the bookings from my database guests have made booking for longer than a certain amount of time. the arrive date and depart date are in booking table. I am working in sqlplus with oracle, and the error invalid identifies…
Hoody
  • 2,942
  • 5
  • 28
  • 32
0
votes
1 answer

Insert datatime value from ASP.NET gridview to SQL Server Datatable

I have a column in ASP.NET gridview that displays the date value in this format (dd/mm/yyyy 00:00:00) upon page load. This is bound to an SQL table with a column declared as "Date" type. In the footer template, there is an "Insert" button as well as…
0
votes
2 answers

how to get diff b/w 2 columns which is in time format

I've 2 columns called record time and unload time which is in time format AM/PM and I require a new column called total time where I need to find difference between unload time and record time... for example here is my table record time unload…
vani
0
votes
2 answers

how to get max of every month of every year

wel if you have a mastertable any columns example mastertable columns createdon,modifiedon,name,id detailtable has createdon,modifiedon,name,id,mastertableid now every month is added automatically a row on master and it could have many rows on…
angel uc
  • 279
  • 2
  • 8
  • 21
0
votes
1 answer

Yii syntax for PGSQL date INTERVAL function

I am locked with how to fill the following code $criteria->addSearchCondition('esdate', 'now()-interval \'1 day\'', false, 'AND', '>'); if I use 'now()' alone it could work but as soon as I add the interval function I cannot get it done. I guess…
CedSha
  • 149
  • 2
  • 12
0
votes
1 answer

Insert Date into database table using Zend framework insert method

I have the foll code as: $table_project_win = new Application_Model_DbTable_AfterWinProject(); $data_win = array( 'project_id' => $project_id, 'project_name' => $project, 'project_type_id'…
ryan
  • 333
  • 1
  • 15
  • 28
-1
votes
2 answers

How to extend data with respect to incomplete dates in T-SQL?

I have the first table like below: Node Date Value 01R-123 2023-01-10 09 01R-123 2023-01-09 11 01R-123 2023-01-08 18 01R-123 2023-01-07 87 01R-123 2023-01-06 32 01R-123 2023-01-05 22 01R-123 2023-01-04 16 01R-123 2023-01-03 …
Robin
  • 85
  • 2
  • 12
-1
votes
1 answer

Count of Employee only when first_stamp is between a window of start_dt

I want a count of emp_id only when firststamp date is in a 21 day window depending on startdt. However, I want to count that empid, only when the firststamp either 7 days before the startdt, during the week of startdt, or the next week of startdt.…
-1
votes
1 answer

SQL Case between Date Ranges with HolidayFlag

I'm trying to add days for following up when a holiday falls during one of the scheduled follow up days. In this case July 1 was the charge date and should be followed up on no later than July 5, but in this case July 4 falls during the follow up…
whoop
  • 3
  • 2
-1
votes
2 answers

CASE WHEN function & date function to change now() > to an assumption date

WITH latest AS ( SELECT DISTINCT customer_id, MAX(submitted_on) AS latest_order FROM orders GROUP BY 1 ), AA AS ( SELECT DISTINCT o.customer_id, latest.latest_order, now() - INTERVAL '91 days' AS reference_more_than_90D, now() -…
Woofer
  • 9
  • 3
-1
votes
2 answers

How to get WeekDay in between two days in SQL server

Please help, I have a below sample data. How to find week days "Tuesday" and count between two days. CREATE TABLE EmpDetails1 (id INT, name VARCHAR(25),startdate datetime,enddate datetime) INSERT INTO EmpDetails1…
-1
votes
1 answer

How can I join two tables on an ID and a DATE RANGE in SQL

I have 2 query result tables containing records for different assessments. There are RAssessments and NAssessments which make up a complete review. The aim is to eventually determine which reviews were completed. I would like to join the two tables…
-1
votes
1 answer

Convert Date in Microsoft SQL Server

I have a problem converting a SQL Column (date_column) to 104 date format. In the date column are two different types of dates. One is in dd-mm-yyyy format and the other one is a consecutive number format (39448). I wrote this query to convert the…