Solved

'yyyymmdd' - need help with file formatting

Posted on 1999-01-25
1
1,276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
After hours on line I found a solution which pointed to the inherited Active Directory permissions . You have to give/allow permissions to the "Exchange trusted subsystem" for the user in the Active Directory...
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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