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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Filename extract string as date

Hi Guys

I load in a few Excel Files to my QV doc see example of pathway,

S:\Support\Supports\Weekly to Monthly\19-06-2013-Workflow.xls

For each of these files I have a field 'Name' based on the file name see :

left(filename(),10) as Name

But I need this as DATE format rather than just the text value (as I wish to later on join in with a Time field for another table)

Can anyone advise me how I may do this ?

Thanks


A

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Day(), Month() and Year() need a valid date as argument to return something meaningful.

And your format code must match the string you pass (note the '/' delimiter in your format code).

Try

Date#( left(filename(),2)&mid(filename(),4,2)&mid(filename(),7,4), 'DDMMYYYY')

while I would still prefer something like posted above.

If you have trouble getting this to work, proceed step by step, i.e. first try to cut out the date string from the filename, stop and have a look at the result, then create an appropriate format code and use date#() to interpret this date string.

Finally, use the interpreted date to create something else, like adding a time part and format as interval in hours:

=interval ( Date#() + TimeField, 'hh:mm:ss')

View solution in original post

9 Replies
swuehl
MVP
MVP

If you successfully managed to cut out the string '19-06-2013', then

Date#('19-06-2013','DD-MM-YYYY') as Date

should interprete your string as date.

Not applicable
Author

Thanks a mill for that -

I am looking to join that Date with an already existing time format - so see sample data below :

The problem is I have a field Curr_Txn_Date and this SHOULD hold the date and the time in the format below ,(:mm:ss in excel)

But in some instances there is ONLY the Time in this field -see data for Orange - so in this instance I wanted to extract the Date of the file as the default value for the Date portion - by using the above method and then in the code was hoping to write some sort of identifier like

if(len(Curr_Txn_Date)<8, left(filename(),10)&Curr_Txn_Date,Curr_Txn_Date)

or something like that

What do you think - as you can see the code as Date#() is not giving the format I require

Any advice greatly appreciated

Thanks

A

Product_IdCurr_Activity_DescriptionCurr_Txn_DateDatecode
55001Apple994668:49:4019-06-201319-06-201341444.534490243
55001Orange0:37:4918-06-201318-06-20130.023122685185185
55001banana994668:49:2419-06-201319-06-201341444.534309722
55001pineapple0:33:1818-06-201318-06-20130.023122685185185
55001tomatoe994668:49:2619-06-201319-06-201341444.534309722
swuehl
MVP
MVP

Maybe like

Timestamp(

if(Curr_Txn_Date < 1, date#( left(filename(),10),'DD-MM-YYYY') + Curr_Txn_Date, Curr_Txn_Date)

,'DD-MM-YYYY hh:mm:ss')

as code

Not applicable
Author

Hey Swuel,

Its still not quite doing what I had hoped in excel : ( Say cell B1 had the filename)

Date formula =DATE(MID(B1,7,4),MID(B1,4,2),LEFT(B1,2)) ( Can you advise how I may do THIS is QV load)

Then I would use your formula as below and format as :mm:ss

=IF(LEN(C2)=17,D2+C2,C2)

Worksheet NameOriginal dataDate FormulaConditional Sum
14-06-2013 work11:55:4114/06/2013994547:55:41
14-06-2013 work994547:55:3314/06/2013994547:55:33
17-06-2013 work8:27:0717/06/2013994616:27:07

Any help would really be appreciated

Thanks

A

Not applicable
Author

 

DATE#

(Day(left(filename(),2))&month(mid(filename(),4,2))&year(mid(filename(),7,4)),'DD/MM/YYYY')

I've tried variations of this and I just cant quite get it right for the Date formula

swuehl
MVP
MVP

Day(), Month() and Year() need a valid date as argument to return something meaningful.

And your format code must match the string you pass (note the '/' delimiter in your format code).

Try

Date#( left(filename(),2)&mid(filename(),4,2)&mid(filename(),7,4), 'DDMMYYYY')

while I would still prefer something like posted above.

If you have trouble getting this to work, proceed step by step, i.e. first try to cut out the date string from the filename, stop and have a look at the result, then create an appropriate format code and use date#() to interpret this date string.

Finally, use the interpreted date to create something else, like adding a time part and format as interval in hours:

=interval ( Date#() + TimeField, 'hh:mm:ss')

Not applicable
Author

OMG Swuel

It was the "/" in my format DD/MM/YYYY

I cant believe I didnt realise that - thanks again for all you help and time

A

Not applicable
Author

if(Curr_Txn_Date < 19, Timestamp(Date#( left(filename(),2)&mid(filename(),4,2)&mid(filename(),7,4), 'DDMMYYYY') + Curr_Txn_Date,':mm:ss'), Curr_Txn_Date)as Number

This was the solution

Not applicable
Author

if(Curr_Txn_Date < 19, Timestamp(Date#( left(filename(),2)&mid(filename(),4,2)&mid(filename(),7,4), 'DDMMYYYY') + Curr_Txn_Date,':mm:ss'), Curr_Txn_Date)as Number

This was the solution