• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 900
  • Last Modified:

sql 2005- convert to a short datetime

Hi
I want to convert a datetime to a short datetime so I dont have the time included

I've found the code below but dont know how to use it

(SELECT CONVERT(DATETIME, CONVERT(INT, GETDATE())

Can someone integrate this into my code below ?

Thanks
SELECT DateAdded FROM tblHat WHERE HatID=@HatID

Open in new window

0
CharlieDev
Asked:
CharlieDev
  • 2
3 Solutions
 
pivarCommented:
Hi,

If it's visual you could do this (for instance, change dateformat as needed)

select convert(varchar(10), GETDATE(), 101)

If you don't want the time in the column at all you can do like this

select convert(datetime, convert(varchar(10), GETDATE(), 101))

/peter
0
 
pivarCommented:
And that would be as string in US dateformat:

SELECT convert(varchar(10), DateAdded, 101) FROM tblHat WHERE HatID=@HatID

or as datetime:

SELECT convert(datetime, convert(varchar(10), DateAdded, 101)) FROM tblHat WHERE HatID=@HatID
0
 
Anthony PerkinsCommented:
Simply:
SELECT DATEADD(day, 0, DATEDIFF(day, 0, DateAdded)) DateAdded FROM tblHat WHERE HatID=@HatID
0
 
CharlieDevAuthor Commented:
Thanks
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

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