最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

shell - How can we add a day into date with given format in unixlinux - Stack Overflow

programmeradmin4浏览0评论

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 badges
Add a comment  | 

2 Answers 2

Reset to default 2

Use 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"
发布评论

评论列表(0)

  1. 暂无评论