Highlighted

Extract date from Excel file string

Participant ,
Aug 29, 2018

Copy link to clipboard

Copied

I have file names like this

P_PAUL-QR-20180827183000.xls

Where 20180827183000 indicates 08/27/2018 at 6:30PM

L_PAUL-QQ-20180828140000.xls
Where 20180828140000  indicates 08/28/2018 at 2:00PM

How do I extract the 20180827183000 or the 20180828140000 from the file name string?

Views

297

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Extract date from Excel file string

Participant ,
Aug 29, 2018

Copy link to clipboard

Copied

I have file names like this

P_PAUL-QR-20180827183000.xls

Where 20180827183000 indicates 08/27/2018 at 6:30PM

L_PAUL-QQ-20180828140000.xls
Where 20180828140000  indicates 08/28/2018 at 2:00PM

How do I extract the 20180827183000 or the 20180828140000 from the file name string?

Views

298

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 29, 2018 0
LEGEND ,
Aug 29, 2018

Copy link to clipboard

Copied

The portion that you want is always 14 integers in length.  RegEx to the rescue. 

<cfset fileName = {however you are providing it} />

<cfset fnArray = REmatch("\d{14}",fileName) /><!--- returns an array of the matched values --->

<cfswitch expression="#arrayLen(fnArray)#">

    <cfcase value="1"><cfset datetime = fnArray[1] /></cfcase>

    <cfdefaultcase>Either there were zero datetimes, or more than one and I didn't know what to do.</cfdefaultcase>

</cfswitch>

HTH,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 29, 2018 0
BKBK LATEST
Adobe Community Professional ,
Aug 29, 2018

Copy link to clipboard

Copied

<cfscript>

filename="P_PAUL-QR-20180827183000.xls";

dateTimeString=listLast(listFirst(filename, "."), "-");

</cfscript>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 29, 2018 0