• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 906
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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