I have a date string that I can parse and format using the date command from a bash script.
date
But how can I determine how many days ago this date was from my script? I would like to get a number.
You can do date arithmetic:
DATE=01/02/2010 echo $(( ( $(date +%s) - $(date -d "$DATE" +%s) ) /(24 * 60 * 60 ) ))
Convert your date and now in seconds, starting from the era, subtract, divide by the number of seconds per day:
#!/bin/bash ((a = `date -d "Wed Jan 12 02:33:22 PST 2011" +%s`)) ((b = `date +%s`)) echo $(( (ba) / (60*60*24)))
Use date as date for date. Example 5 days ago:
date -d "`date`-5days"
Source: https://habr.com/ru/post/651022/More articles:Android: How to set the generated contextMenu header? - androidPython IOError exception while creating a long file - pythonHow to specify a bitrate for JPEG compression? - image-processingHow does the Global.asax PostAuthenticateRequest event bind? - eventsThe best way to split a form on a cell into a minimum number of rectangles - language-agnosticGCC equivalent to PDB - gccWhy doesn't Maven download jar files, but does plugins load fine? - javaWhat is the Java Category as indicated in the eclipse window? - javaWhy doesn't ASP.NET MVC 3 check my floats correctly? - asp.netgetting width of div element - cssAll Articles