Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2009
    Posts
    16

    Unanswered: How can i get the year of the moment?

    I want to get the result like 2009 of the current date. Is there a function to do so?

    Like getDate().getYear()

    Something like that.

    Also if there is none. I can convert getDate to varchar and substring the date value so i can get the result 2009...

    Also this will be an int value in DB so i want to convert "2009" to 2009.

    How can i do it?

    Please urgent help is needed. If i was not in such a rush i would just read it but i have no time at the moment...

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Manual for datepart
    Code:
    select datepart( year, getdate() )

  3. #3
    Join Date
    Jun 2009
    Posts
    16
    Thank you so much for that document. It will help me a lot.

  4. #4
    Join Date
    Mar 2009
    Location
    Sydney, Australia
    Posts
    258
    Yes. If you are learning, then you need to understand the CONVERT() Function, where it relates to date parts as well; refer "style".
    Code:
    SELECT CONVERT( CHAR(4), GETDATE(), 123 )
    Last edited by Derek Asirvadem; 09-11-09 at 01:01.
    Regards
    Derek Asirvadem (Formerly DerekA)
    Information Architect / Senior Sybase DBA
    Copyright 2009 Software Gems Pty Ltd

    I answer questions from the Original Poster only. If you have a genuine question, as the moderators have requested, start a new thread.

    http://www.softwaregems.com.au

  5. #5
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    select year(getdate())

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •