+ Reply to Thread
Results 1 to 9 of 9

Extracting a date from a file name.

  1. #1
    Registered User
    Join Date
    03-19-2016
    Location
    Southampton, England
    MS-Off Ver
    2007
    Posts
    9

    Extracting a date from a file name.

    Hi All,

    I have over a 1000 movie files in various file formats. Periodically I use a XLS to create a listing of the file names.
    All of the file names include a date year in the YYYY format.
    The files are not named consistently. Here a few examples:

    Air.Force.One.1997.720p.BRrip.x264.YIFY
    Along.Came.A.Spider.2001.Alex Cross Drama w. Morgan Freeman 122m
    American Sniper (2014) DvD Scr Rip - X264 1080p
    Apartment, The 1960.720p.BRRip.x264-x0r
    Apollo.13.1995.720p.BluRay.x264.YIFY

    What i'd like is a function that can extract the YYYY and place it in a cell next to the file name

    I'm not sure if it helps but the date value is always going to be between 1925 and 2016.

    I apologise for asking this question in two forums but i'm unsure which one would be best suited..
    Last edited by NevilleT; 03-19-2016 at 07:23 AM.

  2. #2
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,175

    Re: Extracting a date from a file name.

    You try this...
    =LOOKUP(2,1/SEARCH(ROW($1925:$2016),A1),ROW($1925:$2016))

  3. #3
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Extracting a date from a file name.

    Data in A2,ARRAY formula in B2
    Please Login or Register  to view this content.
    ARRAY formula is used

    To enter ARRAY formula
    Paste the formula
    Press F2
    Press Ctrl+Shift+Enter keys together.
    formula will be covered with{} brackets.
    Attached Files Attached Files

  4. #4
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Extracting a date from a file name.

    Formulas that use the ROW( ) function are vulnerable to new row insertions.

    ROW($1925:$2016)

    If you inserted a new row 1 that would change to:

    ROW($1926:$2017)

    And now you're missing any years 1925.

    Using the INDIRECT function can account for that.

    ROW(INDIRECT("1925:2016"))

    New row insertions will have no impact on that syntax.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  5. #5
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,175

    Re: Extracting a date from a file name.

    @Tony Valko.
    Thank you!

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Extracting a date from a file name.

    You're welcome!

  7. #7
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Extracting a date from a file name.

    Clever solution
    Quote Originally Posted by Phuocam View Post
    =LOOKUP(2,1/SEARCH(ROW($1925:$2016),A1),ROW($1925:$2016))
    Though it's not bulletproof.
    If there happens to be another number (besides the desired year) between 1925 and 2016 within the given string.
    For Example:
    2001: A Space Odessy (1968).whatever

    But I can't imagine if there is a bulletproof method either, given the various inconsistent formats of the string.
    So your formula is probably as good as it can get.

  8. #8
    Registered User
    Join Date
    03-19-2016
    Location
    Southampton, England
    MS-Off Ver
    2007
    Posts
    9

    Re: Extracting a date from a file name.

    Hi All,

    Many thanks to Phuocam and everyone else who offered help.
    The lookup was very elegant and worked really well and only fell over a few times - and this was positive as it highlighted files where the date component was missing.

    Sincere thanks to you all.

    (Best wishes from a cold & dull Southampton in the UK)

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Extracting a date from a file name.

    Quote Originally Posted by Jonmo1 View Post
    So your formula is probably as good as it can get.

    =LOOKUP(2,1/SEARCH(ROW($1925:$2016),A1),ROW($1925:$2016))
    Aside from my previous point about the ROW function...

    =LOOKUP(1E100,SEARCH(ROW($1925:$2016),A1),ROW($1925:$2016))

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Extracting Date from text and formatting to date
    By Jietoh in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-16-2016, 03:43 PM
  2. Extracting data from file in directory and extracting filename
    By brad999 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-20-2014, 11:21 AM
  3. [SOLVED] Opening file and extracting file name and filepath
    By kenadams378 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-06-2013, 06:51 AM
  4. Extracting Attachments from outlook based on subject title /file name and between a date
    By himynameisiain in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-14-2013, 02:14 PM
  5. Replies: 4
    Last Post: 05-31-2013, 11:20 AM
  6. [SOLVED] extracting date that is part of file name
    By kramtelbuab in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-24-2013, 10:52 PM
  7. Creating a .txt file extracting information from a Excel file saving as .resx file
    By AbdallahHajbed in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-19-2012, 09:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1