Solved

# Sybase Date Functions

Posted on 2003-03-27
Medium Priority
56,483 Views
Does Sybase have year() and month() functions for DATETIME type?
0
Question by:Johnny2pints
[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

LVL 6

Accepted Solution

DaniPro earned 252 total points
ID: 8220580
The YEARS function return the number of years since the specified date, the number of years between two specified dates or adds the integer-expression amount of years to the specified date.
Examples:
SELECT YEARS( '1998-07-13 06:07:12' )
returns the value 1998.

The MONTH function returns a number from 1 to 12 corresponding to the month of the given date.
Examples:
SELECT MONTH( '1998-07-13' )
returns the value 7
0

LVL 13

Assisted Solution

alpmoon earned 248 total points
ID: 8222927
Month and years are ASA functions. If you are using ASE, you should use datepart function:

select @month = datepart(mm, @yourdate)
select @year = datepart(yy, @yourdate)

Syntax:
datepart(date_part, date)

You can find more details at:

http://sybooks.sybase.com/onlinebooks/group-as/asg1250e/refman/@Generic__BookView?DwebQuery=datepart
0

Expert Comment

ID: 8229615
This example clearly explain, how to get year.  Replace ur variable at getdate function (returns system date)

1> select getdate()
2> go
--------------------------
Mar 29 2003 11:49AM
(1 row affected)

1> select datepart(year, getdate())
2> go
-----------
2003
(1 row affected)
0

## Featured Post

Question has a verified solution.

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

Check out the latest tech news, community articles, and expert highlights in August's newsletter.
If you're a modern-day technology professional, you may be wondering if certifications are really necessary. They are. Here's why.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
###### Suggested Courses
Course of the Month10 days, 16 hours left to enroll