[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Datepart & Dateadd functions

Posted on 1999-01-25
1
Medium Priority
?
3,121 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Ransomware, the malware that locks down its victim’s files until they pay up, has always been a frustrating issue to deal with. However, a recent mobile ransomware will make the issue a little more personal… by sharing the victim’s mobile browsing h…
What monsters are hiding in your child's room? In this article I will share with you a tech horror story that could happen to anyone, along with some tips on how you can prevent it from happening to you.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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