Calculate date based on another date + number of minutes

G

Golan

Hi all,

I need to write a code which gets a date (in format 'YYYYMMDDhh24MISS')
and number of seconds (X), and returns the date (again in format
'YYYYMMDDHH24MISS') that is X seconds prior to the first date.
Any ideas?

Thanks in advance
 
R

Richard Heathfield

Golan said:
Hi all,

I need to write a code which gets a date (in format 'YYYYMMDDhh24MISS')
and number of seconds (X), and returns the date (again in format
'YYYYMMDDHH24MISS') that is X seconds prior to the first date.
Any ideas?

I suggest you take a long hard look at the standard library functions
prototyped in <time.h>, and then attempt a solution of your own. If you get
stuck, post your best-effort code and maybe we can help you fix it.
 
F

Frederick Gotham

Golan posted:
Hi all,

I need to write a code which gets a date (in format 'YYYYMMDDhh24MISS')
and number of seconds (X), and returns the date (again in format
'YYYYMMDDHH24MISS') that is X seconds prior to the first date.
Any ideas?

Thanks in advance


Well you might want to start by using half a brain cell and breaking the
string up:

#include <string.h>

void Process(char const *p)
{
char year[4+1],month[2+1],day[2+1],
hour[2+1],hour_type[2+1],mins[2+1],secs[2+1];

#define SIZE(arr) (sizeof(arr)/sizeof*(arr))

#define COPY_ADV(x) (\
memcpy((x),p,SIZE((x))-1) \
, (x)[SIZE((x))-1] = 0 \
, p += SIZE((x))-1 )


COPY_ADV(year);
COPY_ADV(month);
COPY_ADV(day);
COPY_ADV(hour);
COPY_ADV(hour_type);
COPY_ADV(mins);
COPY_ADV(secs);

/* Now do some more stuff */

#undef SIZE
#undef COPY_ADV
}
 
D

dcorbit

Golan said:
Hi all,

I need to write a code which gets a date (in format 'YYYYMMDDhh24MISS')
and number of seconds (X), and returns the date (again in format
'YYYYMMDDHH24MISS') that is X seconds prior to the first date.
Any ideas?

Thanks in advance

http://sourceforge.net/projects/aptimelib
http://sourceforge.net/projects/yest
http://sourceforge.net/projects/jday

Some people like to reinvent the wheel.

Others go down to the wheel store and buy a shiny new wheel.

I just traipse on over to Sourceforge. They're giving wheels away.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top