Search code examples
unixcsh

different between two time stamps parsed from log files in vivado


Parsing two log files from vivado , How do I compute the difference of time in minutes?

set start_time = "Wed Jun 12 15:12:30 2019"

set end_time = "Thu Jun 13 01:28:39 2019"

In csh how do I compute start_time - end_time and convert it to minutes?


Solution

  • On Linux with GNU coreutil's date you can use the -d flag to parse a date, and +%s to display it in seconds:

    set start_time = "Wed Jun 12 15:12:30 2019"
    set end_time   = "Thu Jun 13 01:28:39 2019"
    
    @ diff = `date -d "$start_time" +%s` - `date -d "$end_time" +%s`
    
    echo "Took $diff seconds"
    

    With @ varname instead of set varname you can perform arithmetic.

    Note the -d flag isn't portable to all systems, but Wikipedia tells me Vivado only runs on Windows and Linux, so I'll assume you're using Linux ;-)


    I would also recommend against using csh for these sort of tasks if it can be avoided; it lacks functions, good redirection, has a weird parser, and some other issues. Bourne shell scripting is generally considered more robust, as would using Python or another "real" programming language be.