• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Extract date from Excel file string

Participant ,
Aug 29, 2018 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

388

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
community guidelines
LEGEND ,
Aug 29, 2018 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,

^ _ ^

Votes

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
community guidelines
Community Expert ,
Aug 29, 2018 Aug 29, 2018

Copy link to clipboard

Copied

LATEST

<cfscript>

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

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

</cfscript>

Votes

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
community guidelines
Resources
Documentation