470,858 Members | 1,731 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,858 developers. It's quick & easy.

Subtracting time from tm structure

Hi frnds,

I have written a code to get current time

struct tm *locTime;
time_t currentTime;
time( &currentTime );
locTime = localtime(&currentTime );

Suppose now i get output time as 31-DEC-2007 00:00:00

What i want now is i want two strings where in one string i want to subtract time to 2 hours that is one string should have value as 30-DEC-2007 22:00:00 and other string should have value 26 hours less that is 23-DEC-2007 22:00:00

I tried some cases where in i subtracted value but it was not working.Is there a way out for this
Jan 5 '08 #1
1 6815
9,208 Expert Mod 8TB
I don't use this time very often but I think you subtract from the time_t rather than from the struct tm.

That means you keep your times in time_t variables and use library functions to create and display the time_t variables.

The struct tm is statically allocated so all time functions use the same struct tm.
Jan 5 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Robert Schoenert | last post: by
14 posts views Thread by George | last post: by
5 posts views Thread by francescomoi | last post: by
7 posts views Thread by Drunkalot | last post: by
1 post views Thread by Drum2001 | last post: by
1 post views Thread by John | last post: by
2 posts views Thread by Joshua J. Kugler | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.