admin管理员组文章数量:1404755
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"
本文标签: shellHow can we add a day into date with given format in unixlinuxStack Overflow
版权声明:本文标题:shell - How can we add a day into date with given format in unixlinux - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744856085a2628781.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论