Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 8th, 2008, 09:01 PM
Authorized User
 
Join Date: Sep 2008
Posts: 87
Thanks: 1
Thanked 0 Times in 0 Posts
Default datetime from sqlserver

Hi,

I have a table which has a column of type datetime,i want to write a query where i can get only year from my datetime column.


2004-11-16 00:00:00.000 this is the one which i have i required only 2004 on selecting.

Thanks in Advance
Raj

 
Old October 8th, 2008, 09:15 PM
Authorized User
 
Join Date: Sep 2008
Posts: 87
Thanks: 1
Thanked 0 Times in 0 Posts
Default

datepart(yyyy,getDate())

this worked out......

 
Old October 8th, 2008, 09:33 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

But much easier is:
Code:
     Year(getDate())
SQL Server provides Year(), Month(), and Day() functions. You have to use DatePart( ) for some other properties of dates, but not those three.





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQLServer Express lizhaskin SQL Language 1 July 6th, 2007 05:40 AM
SQLserver 2000 vs SQLserver 2005 Express cJeffreywang BOOK: Beginning ASP.NET 2.0 and Databases 0 April 22nd, 2007 09:52 AM
SqlServer instance Angela_SB .NET Framework 2.0 0 February 15th, 2007 05:13 PM
is there anything like array in sqlserver? starnet SQL Server 2000 5 July 19th, 2006 08:01 AM
UTC DateTime to Local DateTime r_ganesh76 SQL Server 2000 1 April 4th, 2005 08:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.