score:1
using bsd date
, you can use the -v
to adjust the time properly.
% date
tue may 22 09:21:50 edt 2018
% date -v 23h -v 59m -v 59s
tue may 22 23:59:59 edt 2018
slightly longer, but saving you from having to remember how many hours are in a day, minutes in an hour, etc, by going to midnight tomorrow, then subtracting one second.
% date -v +1d -v 0h -v 0m -v -0s -v -1s
^ ^ ^ ^ ^
| | | | |
| +-----+------+ subtract one second
| |
| reset to midnight
|
go to tomorrow
(it's a shame -v
can't take a combination. date -v+1d0h0ms-1s
would be nice to type. it's not terribly readable or obvious, but easy to parse if you know how -v
works. whitespace would make it better: date -v "+1d 0h 0m 0s -1s"
. #wishfulthinking)
a simple but fragile approach is to just round up to the nearest multiple of 86400:
$ now=$(date +%s)
$ end_of_day=$(( now - now%86400 + 86399))
but this won't take daylight savings into account for the two days where it may be relevant.
score:5
you can simply specify that with the -d
argument.
i.e. date -d "today 23:59:59" +%s
where today 23:29:59 is used to get the end of the current day
edit : @toby propose the following approach to handle correctly leap seconds -d 'tomorrow 0 -1second
if you want the beginning of the day use
date -d "today 0" +%s
Source: stackoverflow.com
Related Query
- get end of day epoch in shell script bash
- Get Day Of Week in bash script
- Get Formatted Date From Timestamp With Rounded Milliseconds Bash Shell Script
- How do I get the bash date script to return a day of the week relative to a non-current time?
- how to get extract a word from a line in bash shell script
- bash script to ssh into a box and get me to a python shell
- Bash shell script to get email When New file comes Without Inotify
- get the duration of running shell script in linux bash
- Removing newline at end of file using bash shell script
- How can I get the middle value of a shell command in bash script
- Get variable outside WHILE in SHELL BASH script
- Bash Script to get the logs of the day
- Get Formatted Date From Numbers bash shell script
- Bash : Shell Script : Find out if the current (Julian) day is the last day of the month
- How can we execute a string command and then get the result of it to assign a variable in shell script bash
- How to remove files expect first and last file by modification date per day in a folder with bash shell script
- read text file using bash shell script that change some times a day
- How do i terminate my script if i don't get an expected integer value? - BASH Shell Script
- Bash Shell Script to get pattern match and fetch values in the line
- get last command line entry from bash in a tcsh shell script
- How to get extract words from differents lines in file and combine them to another file in bash shell script
- How do I get the directory where a Bash script is located from within the script itself?
- Check existence of input argument in a Bash shell script
- Propagate all arguments in a bash shell script
- Get current directory name (without full path) in a Bash script
- Reliable way for a Bash script to get the full path to itself
- Get current time in seconds since the Epoch on Linux, Bash
- Automatic exit from Bash shell script on error
- How to get a password from a shell script without echoing
- Get just the filename from a path in a Bash script
More Query from same tag
- How to rename files with incrementing numbers to files with that number plus 10
- Using sed to get text starting at a line number and ending with a reg expression pattern
- ssh-agent: Could not open a connection to your authentication agent
- Bash inserts script parameters into string
- How to get a bash script to return true on function key press (for use as a Sylpheed filter)
- Cannot get imgur v3 api request to authorize using curl or other bash utility
- Linux - Can't recursively delete large directories
- Why the ‘sudo nohup python a.py &’ command cannot find numpy?
- How can I safely use an azure account name and account key in a cron job?
- Passing awk results to command after pipe
- /dev/dsp missing in debian and cannot hear festival utterance
- Pass command via variable in shell
- Echo within bash subshell
- Rename files using regex on linux using script
- Output of a shell script is another shell script
- How to use IFS with multiple delimiters?
- I would like to find the process id of a Jenkins job
- PHP CLI - comma-separated key/value pairs wrapped in curly braces - what are they?
- Difference between myFun() and function myFun
- What are the shell statements where expanding a variable with or without double quotes is 100% equivalent?
- FInd and copy multiple files that contain a pattern in Linux
- Parsing log file
- Want to filter gcp docker image digest from container registry
- Cronjob timing out with internal server error
- bash with expect: Help with accessing variables
- bash: /bin/myscript: permission denied
- Manipulating strings (file extensions) in bash using find
- using sed to set a variable works on command line, but not bash script
- Bash skip sleep and go to next loop iteration
- Where do Powershell windows go when opened via a startup script?