473,837 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL DATEADD function

I need help in T-SQL.

I am using DATEADD function and I want to add 6 months to a date. But
it does not return me the rusults, which I want

e.g. SELECT DATEADD(m,'2004 0630') returns 20041230
which is logical correct? But I want it to return end of month (i.e.
20041231)

Any help in this context will be highly appreciated

Abdul N. Khan
Jul 23 '05 #1
2 37623
Try this:

SELECT DATEADD(MONTH,D ATEDIFF(MONTH,3 0,'your date'),30)

e.g.

SELECT DATEADD(MONTH,D ATEDIFF(MONTH,3 0,'2-jan-1996'),30)
=============== =============== =============== ==
1996-01-31 00:00:00.000

This will return the last day of any month specified in 'your date',
so you should easily be able to add a further 6 months to the result of
this.

Jul 23 '05 #2
Abdul N K (ab**********@h otmail.com) writes:
I need help in T-SQL.

I am using DATEADD function and I want to add 6 months to a date. But
it does not return me the rusults, which I want

e.g. SELECT DATEADD(m,'2004 0630') returns 20041230
which is logical correct? But I want it to return end of month (i.e.
20041231)


I don't know your exact specification. This expression gives you the
last day of the month 6 months later if you are at the last day of
month:

declare @d datetime
select @d = '20040630'
SELECT dateadd(DAY, -1, dateadd(MONTH, 6, dateadd(DAY, 1, @d)))

However, for @d = 2004-12-30 you get 2004-06-29, which may not be
correct.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3730
by: Gabe | last post by:
Please see: http://www.showorders.com/test3.asp The code generating the page is as follows: testdate = "1/29/2003 1:00:00 PM" while count <> 5 testdate = dateadd("n",15,testdate) response.write testdate & "<br>"
0
2816
by: Zlatko Matiæ | last post by:
I am currently migrating from MSDE to PostgreSQL and have to rewrite the function that is calculating next date of sampling... In MSDE there is a DateAdd function. I can't find the appropriate function in postgre. Can you help me? The function in MSDE is the following: ALTER FUNCTION dbo.slisp ( @UCESTALOST_BROJ int, @UCESTALOST_JEDINICA nvarchar (50),
4
10175
by: ey.markov | last post by:
Greetings, I have an A2K application where for a report the user enters a month-end date, and the system must gather transactions for that month. No problem, I thought, I'll just use the DateAdd function for the beginning of the date range, like this: Between DateAdd("m",-1,!!) And !!
1
19000
by: C.Davidson | last post by:
Does subject VB.net 2003 support DateAdd function? I have tried to implement the following without success. In my example I tried to simply add 30 months to 9/18/2003 and I get "New date: 12:00:00 AM", no date Example direct from VB Language Reference: Public Overloads Function DateAdd(ByVal Interval As DateInterval,_ ByVal Number As Double, ByVal DateValue As DateTime) As DateTime End Function
0
4464
by: Zlatko Matiæ | last post by:
I am currently migrating from MSDE to PostgreSQL and have to rewrite the function that is calculating next date of sampling... In MSDE there is a DateAdd function. I can't find the appropriate function in postgre. Can you help me? The function in MSDE is the following: ALTER FUNCTION dbo.slisp ( @UCESTALOST_BROJ int, @UCESTALOST_JEDINICA nvarchar (50),
2
4560
by: Rich Raffenetti | last post by:
I have the following code. If I do the dateadd function with dateinterval.minute, it works fine and the date/time value is displayed with zero seconds. If I do the dateadd function with dateinterval.second, an error is thrown saying I have an overflow. I would be happy to know if I am doing something wrong or if I could do it differently to get the seconds to display properly. Const largeInteger As Long = &H1C5EA3B5F585F1F Const...
1
3835
by: kevinSQL | last post by:
Is it possible to dynamically modify the Datepart argument of the DATEADD function in T-SQL 2005. I am trying to do something like this but it's not happy with parameter 1: DECLARE @pp NCHAR(3) SET @pp = 'day' SELECT dateadd(@pp,3,'2007-07-14 12:00:00') Any Ideas will be much appreciated.
4
17825
by: rodrigo21 | last post by:
Hello, I have one form with a field for entering a date 'orderdate' and another field for entering a days interval 'range'. This form is used to preform a query on a travel tickets database, so that I can search for tickets with dates from ('orderdate') till ('orderdate' + 'range'). For achieving this I have the followiong code: "SELECT * FROM viajes WHERE viajes.fecha BETWEEN DATEADD(Day,'". $_GET ."','". $_GET ."') AND '". $_GET...
3
6279
by: Mel | last post by:
When I use the DateAdd function using "DateInterval.Weekday" it does not return the correct date, well at least how I thought the weekday option should work. It is counting weekends and I only want it to count the weekdays (Mon-Fri). How can I get it to work? (using Asp.net 2.0, vb.net) Example: dPlanFD = DateAdd(DateInterval.Weekday, 10, "11/04/2008") 'dPlanFD = #11/14/2008# 'I want it to return #11/18/2008#
0
9696
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10583
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10288
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9420
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7824
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7014
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3128
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.