DATEDIFF (intervalstring, date1, date2)

Returns an integer corresponding to the difference according to intervalString between date1 and date2.

Valid intervals are d,dd,w,ww,m,mm,q,y,yy,yyyy,h,hh,n,s

See also: DATEADD, DATEFIFFMILLISECOND, DATEPART, DATESERIAL

Was this article helpful?
0 out of 1 found this helpful

Comments

2 comments
  • Example:

    A CSV file with citizen name and Birthdate (DD-MM-YYYY):

    The ETL project:

    The script (the whole ETL project):

    LOAD ASSEMBLY 'TARGIT.Csv.dll' //server
    DATASOURCE [CSV] = DOTNET CONNECTION 'TARGIT.CSV.CsvConnection' 'HasHeaders=true;loadasstring=false;type=local;delimiter=;
    ;encoding=Windows-1252;culture=en-US;detectionrowscount=100;skiplines=0;'
    IMPORT [tmpCitizenAge] = [CSV].{SELECT * FROM [C:\Data\TestCSV\CitizenAgeFile.csv]}
    IMPORT [CitizenAge] = [ME].{SELECT 
    [Citizen],
    CAST([BDate] as DATETIME) as [BDate],
    DATEDIFF('y',CAST([BDate] as DATETIME),DATE()) as [Age]
    FROM [tmpCitizenAge]}
    SAVE

    Result, based on script being run on the 11th October 2023:

    0
  • Valid interval should be enclosed in single quotes, e.g.:

    datediff('hh', StartTime, StopTime)

    0

Please sign in to leave a comment.