adding time

I want to write a little script that will add 24:00 to the current time if the current time is in between 00:00 and 05:00. I want to make this new time a brand new file so I can work with it. I am not sure how to do this.

variable = current time on our system ( I will pull this)

example:

if (variable) is in between 00:00 and 05:00
then
(variable) + 24:00 = newfile

an example might look like this :

if the time I pull is 00:25 then add 00:25 to 24:00 and get 24:25 and put the 24:25 in a brand new file.

Thanks,

ngg

You should clarify your requirements. What time is 24:15 supposed to represent? A day does not extend past 24 hours. But if we ignore that, you just get the hours and minutes using the "date" command. Then you add 24 to the hours if you want to. Where are you stuck? Also what language are you using?

If you are going to respond, please try to answer my question instead of asking me why I am doing what I am doing. Obviously, I have a good reason for doing it or I would not be posting this.

Perderabo is right. His questions are genuine.

#!/usr/local/bin/bash

HOURS=`date +%H`
MINUTS=`date +%M`

if [[ $HOURS -lt 5 ]]
then
let "HOURS +=24"
fi

echo "${HOURS}:${MINUTS}"

but Perderabo said that hourt must be {0..23}. You must update this script for right calculate of hours.

Thank you azbest. This needs to be an automated script and your example is working just like I need it to.

That will not work on many systems. Do not use a shebang unless you know the location of the executable on the target system.

That will fail if the date changes between one date call and the next. Better (and faster) is:

eval "$( date "+HOURS=%H MINUTS=%M" )"

It is best to avoid the non-portable syntax; use:

if [ $HOURS -lt 5 ]

Another case of non-portable syntax. This will work in all POSIX shells:

HOURS=$(( $HOURS + 24 ))