Calculate date based on another date + number of minutes

Discussion in 'C Programming' started by Golan, Sep 14, 2006.

  1. Golan

    Golan Guest

    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
     
    Golan, Sep 14, 2006
    #1
    1. Advertising

  2. 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.

    --
    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)
     
    Richard Heathfield, Sep 14, 2006
    #2
    1. Advertising

  3. 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
    }

    --

    Frederick Gotham
     
    Frederick Gotham, Sep 14, 2006
    #3
  4. Golan

    Guest

    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?
    >
    > 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.
     
    , Sep 16, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hupjack
    Replies:
    4
    Views:
    789
    hupjack
    May 5, 2004
  2. dee
    Replies:
    15
    Views:
    16,866
    Juan T. Llibre
    Jul 15, 2005
  3. Laery
    Replies:
    11
    Views:
    989
    Laery
    Feb 25, 2005
  4. jochen scheire

    Calculate field based on another field in form

    jochen scheire, Apr 21, 2004, in forum: Javascript
    Replies:
    6
    Views:
    196
    Mick White
    Apr 22, 2004
  5. Replies:
    5
    Views:
    165
Loading...

Share This Page