Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 56761
  • Last Modified:

Sybase Date Functions

Does Sybase have year() and month() functions for DATETIME type?
0
Johnny2pints
Asked:
Johnny2pints
2 Solutions
 
DaniProCommented:
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
 
alpmoonCommented:
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
 
MalleshCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now