Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to truncate the date in sql server 2005

Author  Topic 

pmotewar
Yak Posting Veteran

62 Posts

Posted - 2009-05-10 : 02:18:10
Hi all,

i want to truncate the date

Eg. if my date is 07/01/2008 then i want out put 01/01/2008
or

if my date is 12/01/2008 then i want out put 01/01/2008

how can i get this result.


Pankaj

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-10 : 02:30:11
if your posted date was in dd/mm/yyyy format then use below

SELECT DATEADD(mm,DATEDIFF(mm,0,Yourdateval),0)
if its in mm/dd/yyyy then use below

SELECT DATEADD(yy,DATEDIFF(yy,0,Yourdateval),0)
Go to Top of Page

pmotewar
Yak Posting Veteran

62 Posts

Posted - 2009-05-10 : 03:19:24
quote:
Originally posted by visakh16

if your posted date was in dd/mm/yyyy format then use below

SELECT DATEADD(mm,DATEDIFF(mm,0,Yourdateval),0)
if its in mm/dd/yyyy then use below

SELECT DATEADD(yy,DATEDIFF(yy,0,Yourdateval),0)




Thanks

Pankaj
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-10 : 03:27:20
welcome
Go to Top of Page
   

- Advertisement -