Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 889
  • Last Modified:

SQL Dateformat problem

I wish to convert a datetime value to a string in the format YYYYMMDD where YYYY is the year, MM is the month with leading zero if appliccable and DD is the day, also with leading zero if appliccable.

EG. for 4th may 2006 the string would be 20060504

I am using microsoft SQL Server (2005)

Thanks,

Roger
0
alcindor
Asked:
alcindor
1 Solution
 
Kinger247Commented:
Try : select convert(varchar(8), convert(datetime, getdate(), 112), 112)

where getdate() is your date !
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

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

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