Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date problems 2

Status
Not open for further replies.

maggielady

Technical User
Jan 3, 2003
60
0
0
US
I have a field (character) with a date in it like so 03/17/64. I need to put it in a string format. I have that part, dtos(birthdate), the problem comes in when the birthdate doesn't have a year, ie: 03/17/ I need to be able to put this in a character field in this format yyyymmdd. If the birthdate doesn't have a year, I need it to be ^^^^0317, the ^are spaces, in the new field. Help Please??, Thanks in advance!!
 
MyDate = "11/09/"

? PADL( SUBSTR(MyDate,7,4) + SUBSTR(MyDate,4,2) + SUBSTR(myDate, 1, 2), 8, " ")


I like work. It fascinates me. I can sit and look at it for hours...
 
Actually it could be a lot more complicated than that! Do all you dates have only a 2 digit year?

I like work. It fascinates me. I can sit and look at it for hours...
 
Yes, all my years are 2 digit, but I need them to be four digit. They are all in the 1900's. Your first posted worked great, I forgot about having to have a 4 digit year.
Thanks!!
 
Actually when I fully tried this I couldn't get the new date to be right justified with spaces when replace a field in a table, it was always appearing in the middle!

Maybe someone could spot the problem?

Anyway here's a procedure that should catch all permutations of your dates, but with '0000' for a blank year:

Code:
CREATE CURSOR curMyDates( Old_Date C(10), New_Date C(8) )
INSERT INTO curMyDates ( Old_Date) VALUES ( '11/09/1970' )
INSERT INTO curMyDates ( Old_Date) VALUES ( '11/09/70' )
INSERT INTO curMyDates ( Old_Date) VALUES ( '11/09/' )
INSERT INTO curMyDates ( Old_Date) VALUES ( '11/09' )

SELECT curMyDates
SCAN

	REPLACE New_Date WITH YYYYMMDD(Old_Date) IN curMyDates

	SELECT curMyDates
ENDSCAN

GO TOP
BROWSE

***********************************************
PROCEDURE YYYYMMDD
	LPARAMETERS tcDate
	LOCAL lcRetVal

	DO CASE

		CASE LEN(ALLTRIM(tcDate)) = 10
			lcRetVal = DTOS(CTOD(tcDate))

		CASE LEN(ALLTRIM(tcDate)) = 8
			lcRetVal = "19" + SUBSTR(tcDate,7,2) + SUBSTR(tcDate,4,2) + SUBSTR(tcDate, 1, 2)

		*** Note four zeros instead of spaces as I couldn't get them to stay right justified
		*** in the table!
		CASE LEN(ALLTRIM(tcDate)) = 5 OR LEN(ALLTRIM(tcDate)) = 6
			lcRetVal = '0000' + SUBSTR(tcDate,4,2) + SUBSTR(tcDate, 1, 2)

		OTHERWISE
			lcRetVal = ""

	ENDCASE

	RETURN lcRetVal

ENDPROC

I like work. It fascinates me. I can sit and look at it for hours...
 
Hi Neil! (wasn't that your real name FatSlug?)

No problem, when replacing those '0000' with space(4)
the result is still right aligned, only doesn't look
so in the normal browse window font Arial.
If you set the font for browse windows to courier new,
it just looks fine.

Bye, Olaf.
 
Hi Olaf!

Thanks for the info! It was driving me mad yesterday! Even printing just to screen showed the value centred unless a charatcer was used instead of a space!

And yes, my real name is Neil :)

FatSlug

I like work. It fascinates me. I can sit and look at it for hours...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top