Solved

Datepart & Dateadd functions

Posted on 1999-01-25
1
3,015 Views
Last Modified: 2008-02-01
Hi,
I am a newbie to Sybase. Could someone enlighten me about the datepart & dateadd functions, with an example.

Thanks,
V
0
Comment
Question by:Vignesh071498
1 Comment
 

Accepted Solution

by:
kavitag earned 50 total points
ID: 1098592
Datepart returns the value of (month,day or year) of a date.
Dateadd adds the days, minutes, hours, seconds, months, years to the date and returns the newdate.

Example:
getdate() is the function that returns the current date and time.
select datepart(MM,getdate()) returns the value of month as integer ie 1.
select datepart (YY,getdate()) returns year part , 1999.
Pass other formats to get the hour, minute, second, day part of the date.
Other formats are hh for hour, ss for seconds, dd for days. I am not sure about the format for minutes.

declare @to_date datetime

select @to_date = dateadd(MM,2,getdate())
adds 2 months to today and returns the new value to @to_date.
changing MM to YY adds 2 years to current date. etc.
add years, days, hours, minutes, seconds to a date. Add positive or negative integer to the date.


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many Password Managers (PM) out there to choose from. PM's can help with your password habits and routines, but they should not be a crutch you rely on too heavily. I also have an article for company/enterprise PM's.
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now