- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Date conversion and calculating elapsed times
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
тАО08-01-2002 12:28 AM
тАО08-01-2002 12:28 AM
Date conversion and calculating elapsed times
Does anyone know how to convert a date/time into seconds and then calculate the elapsed time between two times?
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2002 12:39 AM
тАО08-01-2002 12:39 AM
Re: Date conversion and calculating elapsed times
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include
#include
#include
#include
#include
int main(argc, argv)
int argc;
char *argv[];
{
struct tm st_time, en_time;
time_t start, finish;
double diff_time;
if (argc != 13)
{
printf("usage: timediff fm_yr fm_mon fm_day fm_hr fm_min fm_sec to_yr to_mon to_day to_hr to_min to_sec\n");
printf(" where fm_yr and to_yr are years in 4 digits\n");
printf(" and fm_hr and to_hr are hours in 24 hours time.\n\n");
printf("timediff returns the difference of two inputs in seconds\n");
}
else
{
st_time.tm_year = atoi(argv[1])-1900;
st_time.tm_mon = atoi(argv[2])-1;
st_time.tm_mday = atoi(argv[3]);
st_time.tm_hour = atoi(argv[4]);
st_time.tm_min = atoi(argv[5]);
st_time.tm_sec = atoi(argv[6]);
st_time.tm_isdst = 0;
en_time.tm_year = atoi(argv[7])-1900;
en_time.tm_mon = atoi(argv[8])-1;
en_time.tm_mday = atoi(argv[9]);
en_time.tm_hour = atoi(argv[10]);
en_time.tm_min = atoi(argv[11]);
en_time.tm_sec = atoi(argv[12]);
en_time.tm_isdst = 0;
finish = mktime(&en_time);
start = mktime(&st_time);
/*
printf("%ld, %s", start, ctime(&start));
printf("%ld, %s", finish, ctime(&finish));
*/
diff_time = difftime(finish,start);
/*
printf( "\nDelay time = %6.0f seconds.\n", diff_time );
*/
printf( "%-6.0f\n",diff_time );
}
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2002 12:43 AM
тАО08-01-2002 12:43 AM
Re: Date conversion and calculating elapsed times
Somethink in Korn shell would be nice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2002 03:24 AM
тАО08-01-2002 03:24 AM
Re: Date conversion and calculating elapsed times
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xea948cc5e03fd6118fff0090279cd0f9,00.html
Hope This Helps,
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2002 07:05 AM
тАО08-01-2002 07:05 AM
Re: Date conversion and calculating elapsed times
start_time=$SECONDS
sleep 5
end_time=$SECONDS
elapsed_time=expr $start_time - $end_time`
echo $elapsed_time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2002 07:06 AM
тАО08-01-2002 07:06 AM
Re: Date conversion and calculating elapsed times
it should be like this,
elapsed_time=expr $end_time - $start_time`