Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

how to extract date from filename

i have a doubt can you clarify me i have a data in which i have to retrieve date from excel name i have done using

left(right(filenmae)2)1)

but i have doubt if have date in 29-jan-2016 how can i get date without using left and right function how ever the data may be i should get it dynamicly

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

Use this.... to extract date field... it should work..

Date(Alt(

     Date#(SubField(FileBaseName(),'_',-1),'DD-MMM-YYYY'),

     Date#(SubField(FileBaseName(),'_',-1),'DD-MMMM-YYYY'),

     Date#(SubField(FileBaseName(),'_',-1),'DD-MM-YYYY')

     )) as Date

View solution in original post

9 Replies
MK_QSL
MVP
MVP

What is the filename?

Not applicable
Author

MAC_R2_CR_PBTV_ACCOUNTS_04-july-2016

MK_QSL
MVP
MVP

LOAD

     Date(Date#(SubField(FileBaseName(),'_',-1),'DD-MMM-YYYY')) as Date

FROM

YourFile

or

LOAD

     Date(Date#(SubField(FileBaseName(),'_',-1),'DD-MMMM-YYYY')) as Date

FROM

YourFile

Not applicable
Author

thanks Manish i have doubt i want to retrieve date dynamically what ever the format the date is like

MAC_R2_CR_PBTV_ACCOUNTS_04-july-2016

MAC_R2_CR_PBTV_ACCOUNTS_04-07-2016


MK_QSL
MVP
MVP

LOAD

  Date(Alt(

     Date#(SubField(FileBaseName(),'_',-1),'DD-MMM-YYYY'),

     Date#(SubField(FileBaseName(),'_',-1),'DD-MMMM-YYYY'),

     Date#(SubField(FileBaseName(),'_',-1),'DD-MM-YYYY')

     )) as Date

FROM

[MAC_R2_CR_PBTV_ACCOUNTS_*.xlsx]

(ooxml, embedded labels, table is Sheet1);

Not applicable
Author

no Manish i am asking the file name may be either like this


MAC_R2_CR_PBTV_ACCOUNTS_04-july-2016

or

MAC_R2_CR_PBTV_ACCOUNTS_04-07-2016

however it is it should work in a single expression

MK_QSL
MVP
MVP

Use this.... to extract date field... it should work..

Date(Alt(

     Date#(SubField(FileBaseName(),'_',-1),'DD-MMM-YYYY'),

     Date#(SubField(FileBaseName(),'_',-1),'DD-MMMM-YYYY'),

     Date#(SubField(FileBaseName(),'_',-1),'DD-MM-YYYY')

     )) as Date

Not applicable
Author

great manish tanks for your help

MK_QSL
MVP
MVP

If you have got the correct solution, kindly close the thread by selecting correct answer.. this will help others having same issue.