Velocity Reviews > Calculate date based on another date + number of minutes

# Calculate date based on another date + number of minutes

Golan
Guest
Posts: n/a

 09-14-2006
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?

Richard Heathfield
Guest
Posts: n/a

 09-14-2006
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

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

Frederick Gotham
Guest
Posts: n/a

 09-14-2006
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?
>

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))

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

/* Now do some more stuff */

#undef SIZE
}

--

Frederick Gotham

dcorbit@connx.com
Guest
Posts: n/a

 09-15-2006

Golan wrote:
> 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?
>

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.

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Michael ASP General 5 03-15-2007 11:10 AM Laery C Programming 11 02-25-2005 07:59 AM Peter Grison Java 10 05-30-2004 01:20 PM hupjack Perl 4 05-05-2004 03:42 PM jochen scheire Javascript 6 04-22-2004 01:47 PM