Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to Convert 7 or 8 character numeric string to date

Hello.

Hopefully the Qlik Community can assist me. I am attempting to load from a *.csv file a series of dates formatted as a text string. The text string varies in length between either a 7 or 8 character string which is either DMMYYYY (7 character string) or DDMMYYYY (8 character string).

In the load statement I would like to have these text string converted to the date format DD-MM-YYYY.

For example my data looks like:

NameDate_of_birth (as text string)Wanted Date Format
John Smith110198301/01/1983
Dee White2712197527/12/1975
Marg All1606200116/06/2001
Win Cooper910201209/10/2012
Sam Mac707200707/07/2007
Wanda McT509196205/09/1962
Steve Rudd2102196421/02/1964
Tim Jurd1801193818/01/1938

How can I accomplish this?

So far I have tried combinations of several statements including:

IF (LEN(Date_of_birth]) = 7, '0' & Date_of_birth, Date_of_birth) as Date_of birth,  this worked to make the 7 character string to an 8 character string


Also I tried converting to date using


Date(Date# ([Date of birth],'DDMMYYYY'), 'DD-MM-YYYY') as [Date of birth], but this gives me incorrect dates, for example 7 character string 2111934 gives me 21-11-0934, where I am expecting 02/11/1934. While 8 character string 15121991 is interpreted correctly as 15-12-1991.

1 Solution

Accepted Solutions
effinty2112
Master
Master

Hi Matthew,

Try

Date(Date#(Right('0' &[Date_of_birth (as text string)],8),'DDMMYYYY'),'DD/MM/YYYY')

in a chart or in script as you prefer.

giving

Date_of_birth (as text string) Date(Date#(Right('0' &[Date_of_birth (as text string)],8),'DDMMYYYY'),'DD/MM/YYYY')
110198301/10/1983
509196205/09/1962
707200707/07/2007
910201209/10/2012
1606200116/06/2001
1801193818/01/1938
2102196421/02/1964
2712197527/12/1975

Cheers

Andrew

View solution in original post

2 Replies
effinty2112
Master
Master

Hi Matthew,

Try

Date(Date#(Right('0' &[Date_of_birth (as text string)],8),'DDMMYYYY'),'DD/MM/YYYY')

in a chart or in script as you prefer.

giving

Date_of_birth (as text string) Date(Date#(Right('0' &[Date_of_birth (as text string)],8),'DDMMYYYY'),'DD/MM/YYYY')
110198301/10/1983
509196205/09/1962
707200707/07/2007
910201209/10/2012
1606200116/06/2001
1801193818/01/1938
2102196421/02/1964
2712197527/12/1975

Cheers

Andrew

Anonymous
Not applicable
Author

Thank you Andrew, your solution works perfectly.

For those that may be reading along I did remove the text " (as text string)" to get it to work.

I wouldn't of been able to come up with that one myself. This will help me read correctly the 10 or other date fields in my data set.