Questions tagged [dateadd]

dateadd is a T-SQL function that returns a datetime with the specified number interval added to a specified datepart of that datetime.

dateadd(datepart,number_of_units,date_time_value) is a T-SQL function available in MS SQL Server and the SAP/Sybase family of database products that can add and subtract from datetime values. Subtraction is accomplished by using a negative number_of_units value.

datepart is usually a two letter code which specifies which date or time segment is being added number of units is a signed int value that specifies how much to add to the datepart date_time_value is the datetime that is being manipulated.

SQL Server Syntax

SAP/Sybase Syntax

498 questions
-1
votes
2 answers

Add a week to a range of dates in VBA

In sheet INPUT, rows of data for week schedule gets inputted. Multiple rows per day is possible. Column A contains the dates of the original week of the schedule. When the complete planning is set in the INPUT sheet (lets say 15 rows by 10 columns…
-1
votes
1 answer

setGregorianChange(new Date(Long.MIN_VALUE)) does not convert the calendar to pure GregorianCalendar

GregorianCalendar test= new GregorianCalendar(); BigDecimal coef=new BigDecimal(-2113480800); test.setGregorianChange(new Date(Long.MIN_VALUE)); test.set(Calendar.DAY_OF_MONTH, 31); test.set(Calendar.MONTH, 11); test.set(Calendar.YEAR,…
-1
votes
4 answers

Select the last 7 days of each month

I am using SQL Server 2008. I'm looking to bring back only the last 7 calendar days of each month, how would I go about doing this. Thanks
userleo87
  • 1
  • 3
-1
votes
4 answers

How to add/subtract days from a date

Let's say I have this table : DECLARE @Var INT SET @Var = (select day from source) SELECT * FRom TMP INTO #TARGET Where tmp.date >= dateadd(day,datediff(day,0,GETDATE()),0) - @Var tmp.date <=…
stoner
  • 417
  • 2
  • 12
  • 22
-1
votes
1 answer

Migrate Oracle SQL and Sql Server on new Date

I want to make a query which is compatible for Oracle SQL and PL/SQL. I use the Dateadd function in SqlServer, which is incompatible for Oracle, there you can use ADD_MONTHS. Sql Server: DATEADD(MONTH, -1,…
Jonas
  • 769
  • 1
  • 8
  • 37
-1
votes
1 answer

Why does PHP DATE_ADD() function returns a syntax error

Im trying to populate a table using some other specific tables(there's a set of tables known as table_1,table_2,table_3 etc) in the same database by giving a date interval(to obtain rows which are recorded within a month). below is the code im…
Prog_Rookie
  • 438
  • 7
  • 23
-1
votes
4 answers

How do I get records from starting at 12 o clock on specified days?

Hey I'm running sql server & inside my where clause I have about 6 of these conditions for different date ranges. The dateadd functions work great, maybe too good in my case. I am missing records because inside the DB if the record has a timestamp…
Bgreen
  • 27
  • 1
  • 9
-1
votes
1 answer

Why is where clause only returning one result when I know theirs multiple hits?

Only returns one record when i know their are records in the db that meet criteria for 3 of the date portions. Could it be the chaining of the and or's ? The one record that is returned falls into it's proper range which made me place blame on the…
Bgreen
  • 27
  • 1
  • 9
-1
votes
1 answer

DATE_ADD sql in PHP PDO

I am trying to insert a new row in my database with a date and the same date plus 1 week. I use PDO in php, don't know if it is relevant. This is the code which fails: $stmtEncInsert = $db->prepare("INSERT INTO test …
Biribu
  • 3,615
  • 13
  • 43
  • 79
-1
votes
1 answer

VB DateAdd to String

Im trying to get the DateAdd function as a string So far i got Dim newDate newDate = DateAdd("m", 1, date) MsgBox(newDate.ToString("d")) Which gets error object required Im trying to create a photoshop script that gets the date and adds on 1…
Tony Sawlwin
  • 146
  • 1
  • 19
-1
votes
1 answer

adding recurring employee holidays in sql server

i currently have this table in SQL server: PL_ID User_ID Log_Date Out_Time In_Time Reason Details PL stands for people logger... then you have the user ID, the log date (date of day off), out time, in time, reason and details... there is a…
-2
votes
2 answers

Using SQL to select data from last week

What is the best way to select data from the previous week? The below returns a syntax error. SELECT COUNT(dbo.Calls.kbpCallID) NoofoutboundCalls FROM (((dbo.Calls LEFT OUTER JOIN dbo.OrganizationContacts ON dbo.Calls.kbpOrganizationID…
ESwift
  • 19
  • 4
-2
votes
2 answers

Convert WHERE clause to CASE expression

Can someone please help me rewrite this using a CASE (using easy to read syntax): SELECT * FROM TBL_A WHERE COLUMN_A BETWEEN DATEADD(MONTH, DATEDIFF(MONTH, +1, GETDATE()), 0) AND DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE()),…
Ishy
  • 9
  • 4
-2
votes
2 answers

sql update next day no row effect

I want update tomorrow if today overtime work. But I have some problem no row effect. lembur_time = overtime work type data int update kkpsurabaya set clock_in='' where lembur_time >=240 and name='yuyun dwi astutik' and date =…
-3
votes
2 answers

Add a new date row for every day where greater than a date column and less than another date column?

I am trying to add in SQL Server table a new row for every day between two columns, start and end date columns. Here is a sample table. Add a new row for every day between order and shipping dates, including the start and end dates. Name Date of…
Cave Man
  • 45
  • 5
1 2 3
33
34