Solved

'yyyymmdd' - need help with file formatting

Posted on 1999-01-25
1
1,260 Views
Last Modified: 2008-03-10
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
Comment
Question by:alla012599
1 Comment
 
LVL 7

Accepted Solution

by:
spiridonov earned 30 total points
ID: 1098593
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There's a lot of hype surrounding blockchain technology. Here's how it works and some of the novel ways it' s now being used - including for data protection.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question