Date Format - 2025-11-03T20:39:00+05:30
I need to take this date into a variable, add 24hrs to it and store into another variable. Suggestions are appreciable as I'm new to linux coding.
Date Format - 2025-11-03T20:39:00+05:30
I need to take this date into a variable, add 24hrs to it and store into another variable. Suggestions are appreciable as I'm new to linux coding.
Share asked Mar 10 at 8:40 MeenalMeenal 1477 silver badges18 bronze badges2 Answers
Reset to default 2Use date
command:
save to variable:
$ export savedDate=2025-11-03T20:39:00+05:30
add 24hrs to savedDate
and store it:
$ export updatedDate=$(date -d "$savedDate + 1 day" +"%Y-%m-%dT%H:%M:%S+5:30")
show result:
$ echo $savedDate && echo $updatedDate
for more information, use:
$ date --help
Here's a simple way to take your date string, add 24 hours, and store it into another variable.
#!/bin/bash
# Original date string
date_string="2025-11-03T20:39:00+05:30"
# Convert it to UTC first (because of the +05:30 timezone offset)
# and add 24 hours, then format it back
new_date=$(date -d "$date_string 24 hours" --iso-8601=seconds)
echo "Original Date: $date_string"
echo "Date after 24 hours: $new_date"
if you want store them in variable
original_date="$date_string"
updated_date=$(date -d "$original_date 24 hours" --iso-8601=seconds)
echo "Original Date: $original_date"
echo "Updated Date (+24 hrs): $updated_date"