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

'yyyymmdd' - need help with file formatting

Hello.
here is the problem: I need to create a text file in Sybase where one of the values has the format char(8) 'yyyymmdd'. There is no such format in Sybase's convert function.  So, I use convert(char(4),datepart(yy,GetDate())) + same for month and + same for day.The problem is when month is 1, I get 1999125 which means 1999 Jan 25, and even if I add a space to make it up to 8 characters it does not resolve the problem, because it is not clear if 1999125 1999 Dec 5 or 1999 Jan 25.
Does anyone know how to select 19990125 meaning 1999 Jan 5th?
0
alla012599
Asked:
alla012599
1 Solution
 
Victor SpiridonovCommented:
Use Case statement and datalength function:
(CASE DATALENGTH(CONVERT(VARCHAR(2),datepart(yy,getdate()))) WHEN 1 then CONVERT(VARCHAR(2),datepart(yy,getdate())) ELSE '0'+CONVERT(VARCHAR(2),datepart(yy,getdate())) END)
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.

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