Page 3 of 3 FirstFirst 123
Results 21 to 23 of 23

Thread: command to to find difference between dates

  1. #21
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    2,475

    Default Re: command to to find difference between dates

    Quote Originally Posted by lord_valarian View Post
    Code:
    #date --date="11/12/2018 09:04:34pm" '+%s'
    This is the base code I found on a website. In my code, the larger the date difference, the worse the error. So, either this base code is the wrong method of date
    conversion or the date command has a bug.

    It looks like the bash 'date' command conversion isn't taking into account extra days in some months. NOV 30 days, DEC 31 days. Unless, I missed something that code should work.
    Are you being confused by US American date/time formats versus ISO and RFC date/time formats:
    • “11/12/2018” usually means “Monday the 12th of November 2018” …


    BTW:
    Code:
     > LANG=C date --date='11/31/2018 09:04:34pm'
    date: invalid date '11/31/2018 09:04:34pm'
     > 
     > LANG=C date --date='11/30/2018 09:04:34pm'
    Fri Nov 30 21:04:34 CET 2018
     > 
     > LANG=C date --date='02/31/2018 09:04:34pm'
    date: invalid date '02/31/2018 09:04:34pm'
     > 
     > LANG=C date --date='02/29/2018 09:04:34pm'
    date: invalid date '02/29/2018 09:04:34pm'
     > 
     > LANG=C date --date='02/28/2018 09:04:34pm'
    Wed Feb 28 21:04:34 CET 2018
     >

  2. #22

    Default Re: command to find difference between dates

    Quote Originally Posted by dcurtisfra View Post
    Are you being confused by US American date/time formats versus ISO and RFC date/time formats:
    • “11/12/2018” usually means “Monday the 12th of November 2018” …


    I want to allow for different date formats in the scanvirus logs. Using a 'seconds since 1970' field, I will be able to be much more flexible. Else, I need standard date as the first field to keep the code from becoming too complex.

    [standard time field] [scanvirus log fields]

    Code:
    # date --date="11/12/2018 09:04:34pm" '+%s'
    1542085474
    standard date --> seconds since 1970

    This base code conversion doesn't work, there is a negative progressive error.

    Code:
    Clean Scan: linux 11-07-2018 04:25:55pm {}   5 
    Clean Scan: linux 11-07-2018 05:01:49pm {}   5 
    Clean Scan: linux 11-07-2018 05:21:34pm {}   5 
    Clean Scan: linux 11-08-2018 01:21:37pm {}   5 
    Clean Scan: linux 11-11-2018 01:14:36pm {}   4 
    Clean Scan: linux 11-11-2018 01:38:24pm {}   4 
    Clean Scan: linux 11-12-2018 12:57:02pm {}   4 
    Clean Scan: linux 11-12-2018 08:44:07pm {}   3 
    Clean Scan: mswin 11-12-2018 08:45:36pm {;}   3 
    Clean Scan: linux 11-12-2018 09:04:34pm {}   3 
    Clean Scan: linux 11-13-2018 01:44:37pm {}   3 
    Clean Scan: linux 11-13-2018 02:33:04pm {}   3 
    Clean Scan: linux 11-13-2018 10:24:35pm {}   3 
    Clean Scan: linux 11-14-2018 01:46:56pm {}   3 
    Clean Scan: linux 11-14-2018 08:21:06pm {}   3 
    Clean Scan: linux 11-14-2018 09:05:43pm {}   3 
    Clean Scan: linux 11-16-2018 02:03:40pm {}   2 
    Clean Scan: linux 11-16-2018 09:35:14pm {}   2 
    Clean Scan: linux 11-16-2018 09:35:32pm {}   2 
    Clean Scan: linux 11-18-2018 12:47:23pm {}   1 
    Clean Scan: linux 11-18-2018 12:48:12pm {}   1 
    Clean Scan: linux 11-18-2018 02:03:20pm {}   1 
    Clean Scan: linux 11-20-2018 01:25:38am {}   1 
    Virus Found: mswin 11-20-2018 01:59:50am {Recovery;EFI   7143 
    Clean Scan: linux 11-20-2018 02:13:36pm {}   0 
    Clean Scan: linux 11-22-2018 01:42:07pm {}   0
    Not using integer variables might be the problem. The current date is at the bottom. The right column is the days since current date. Examine those values, you will see a an error.


    I'm learning about the date formats as write the code. I don't have to use [seconds since 1970]. I can use the US standard format as a scanvirus field.

  3. #23

    Default Re: command to to find difference between dates

    I'll have to come back to integer variables and using the date conversion later.

    I was successful in in creating the new log format. Now, you can use any time and date stamp format with affecting the log search. You can still use the old log format, for now.

    'scanvirus -vf' --> navigate to 'usr/bin/' --> search 'scanvirus' --> open scanvirus --> change time_date_stamp to your format --> exit window.


    Thanks for the help.

Page 3 of 3 FirstFirst 123

Tags for this Thread

Posting Permissions

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