- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to calculate time difference in Shell
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2004 05:22 AM
тАО04-27-2004 05:22 AM
for example:
System_Time = 4:36:00PM
My_Time = 9:00:00PM
Can I get something like this..
My_Time - System_Time
I need to check whether this time interval is enough to execute a batch job.
Thank You,
Suman
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2004 05:38 AM
тАО04-27-2004 05:38 AM
Solution#!/usr/bin/sh
get_seconds()
{
typeset -i10 HR=${1}
typeset -i10 MIN=${2}
typeset -i10 SEC=${3}
shift 3
typeset -i10 TOT=$(( (${HR} * 3600) + (${MIN} * 60) + ${SEC} ))
echo "${TOT}"
return 0
} # get_seconds
typeset -i10 H1
typeset -i10 M1
typeset -i10 S1
date '+%H %M %S' | read H1 M1 S1
typeset -i10 H2=21
typeset -i10 M2=0
typeset -i10 S2=0
typeset -i10 DIFF=$(( $(get_seconds ${H2} ${M2} ${S2}) - $(get_seconds ${H1} ${M1} ${S1}) ))
echo "Time left = ${DIFF} seconds"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2004 10:07 AM
тАО04-27-2004 10:07 AM
Re: how to calculate time difference in Shell
How do I find if the parameter_date falls on the 1st day of the month in UNIX.
I have to check for a condition if the parameter_date is the 1st day of any of the 12 months.
Is it possible in UNIX to manipulate dates for example increment date by 1 day?
Thanks
Suman
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2004 10:21 AM
тАО04-27-2004 10:21 AM
Re: how to calculate time difference in Shell
DAY=$(date '%M');
if [[ "${DAY}" = "01" ]]
then
echo "First Day"
fi
However, the general answer to how to manipulate date ranges is the use of this script that someone wrote called caljd.sh.
For example:
This will return the date 3 days from now in MM DD YYYY format:
DT=$(caljd.sh $(caljd.sh -n 3))
echo "Date = ${DT}"
If all you wanted was the month 3 days from now that would be:
MO=$(caljd.sh -M $(caljd.sh -n 3))
echo "Month = ${MO}"
Invoke as caljd.sh -u for full usage and examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2004 10:23 AM
тАО04-27-2004 10:23 AM
Re: how to calculate time difference in Shell
No semicolon at the end:
DAY=$(date '%M');
should be
DAY=$(date '%M')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2004 02:55 AM
тАО04-28-2004 02:55 AM
Re: how to calculate time difference in Shell
I tried this script but it gives me error:
date: bad conversion
#####################
DAY=$(date '%M')
if [[ "${DAY}" = "28" ]]
then
echo "Twenty Eight Day"
fi
######################
Regards
Suman
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2004 02:58 AM
тАО04-28-2004 02:58 AM
Re: how to calculate time difference in Shell
DAY=$(date '+%M')
Do a "man date"; it explains all of your options.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2004 03:03 AM
тАО04-28-2004 03:03 AM
Re: how to calculate time difference in Shell
DAY=`date +%d`
Thanks
Suman
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2004 03:18 AM
тАО04-28-2004 03:18 AM
Re: how to calculate time difference in Shell
for example..
parm_date=20040501
If the parameter date is first of month
then change this parameter date to 1 day back. Actually I need to pass parm_date=20040430 as my argument.
Also my date in the format yyyymmdd with no spaces.
Thanks a lot
Suman
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2004 03:18 AM
тАО04-28-2004 03:18 AM
Re: how to calculate time difference in Shell
If you have a lot of those jobs to do, GNU date would make it easy. It offers the same fetures as your date command, but adds somes :
. converting a date (for example to epoch, that will let you make differences)
. have date for yesterday or n days ago
...
Regards,
Fred
"Reality is just a point of view." (P. K. D.)