Solved

Datepart & Dateadd functions

Posted on 1999-01-25
1
3,004 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A Short Story about the Best File Recovery Software – Acronis True Image 2017
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

11 Experts available now in Live!

Get 1:1 Help Now