?
Solved

Datepart & Dateadd functions

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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Introducing Priority Question, our latest feature.
Hey fellow admins! This time, I have a little fairy tale for you. As many tales do, it starts boring and then gets pretty gory. I hope you like it. TL;DR: It is about an important security matter, you should read it if you run or administer Windows …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

771 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