Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
GOKULAKANNAN
Creator II
Creator II

Convert string to date field

I have a date field like 8092021, which is MMDDYYYY, i just need to change this to Mm/DD/YYYY, but problem is some places MM is having single digit like and in some places its having 2 digits , for ex: 12202021, in this case how can define it

Labels (1)
  • SaaS

6 Replies
Aurelien_Martinez
Partner - Specialist II
Partner - Specialist II

Hi,

You can try :

Date(Date#(Repeat('0', 8-Len('8092021')) & '8092021', 'MMDDYYYY'))

Aurélien

Help users find answers! Don't forget to mark a solution that worked for you!
GOKULAKANNAN
Creator II
Creator II
Author

But in my case , date is a field, how can i apply the same to a field

Aurelien_Martinez
Partner - Specialist II
Partner - Specialist II

With :

Date(Date#(Repeat('0', 8-Len(MyField)) & MyField, 'MMDDYYYY'))

Help users find answers! Don't forget to mark a solution that worked for you!
GOKULAKANNAN
Creator II
Creator II
Author

Can we do the same if the field is number ?

 

Aurelien_Martinez
Partner - Specialist II
Partner - Specialist II

I think. 

I have tried with this data :

Load
  MyDate,

  Date(Date#(Repeat('0', 8-Len(MyDate)) & MyDate, 'MMDDYYYY'))  as Date
Inline [
MyDate
8092021
12202021
];

 

 

Help users find answers! Don't forget to mark a solution that worked for you!
Aurelien_Martinez
Partner - Specialist II
Partner - Specialist II

Or you can try with an if

 

Date(If(Len(MyDate) = 8,
  Date#(MyDate, 'MMDDYYYY'),
  Date#(MyDate, 'MDDYYYY')
)) as Date

Help users find answers! Don't forget to mark a solution that worked for you!