Grabbing a date from a filename

  • Hello all,

    I have the following filename

    GC_20060616_All_Demographics

    I am trying to pull out the date e.g. the number between the _ _ characters and using it as a small date format. This is probably very easy and I have done it before getting a Surname out of a field after a space but Im struggling with this one.

    Thanks in advance

    Debbie

  • hi debbie

    if u r sure that the format(including the length) of the filename will not change then this shud work

    select

    substring('GC_20060616_All_Demographics',(charindex('_','GC_20060616_All_Demographics',1)+1),8)

    "Keep Trying"

  • Fantastic,

    All my files follow the same format so this is working fine

    select DISTINCT CAST(substring(Filename,(charindex('_',FileName,1)+1),8)AS SmallDateTime)

    FROM dbo.FailedExports

    WHERE FileName LIKE 'GC%'

    Thanks again

    Debbie

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply