Solved

Datepart & Dateadd functions

Posted on 1999-01-25
1
3,069 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article outlines some of the reasons why an email message gets flagged as spam on a recipient's end.
We take a look at some of the most common obstacles that IT teams run into as they work relentlessly to keep all the alarms and sirens from going off at once.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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