current date

Discussion in 'C Programming' started by placid, Aug 25, 2005.

  1. placid

    placid Guest

    how would i get the current date in the format of DD/MM/YYYY, do i use
    functions in time.h and how would i compile it (linking) ?
     
    placid, Aug 25, 2005
    #1
    1. Advertising

  2. In article <>,
    placid <> wrote:
    >how would i get the current date in the format of DD/MM/YYYY, do i use
    >functions in time.h


    Yes, use time() to fetch the current time, localtime() to break
    it down into a struct tm, then extract the structure members of that
    that you are interested in and print them yourself.

    Caution: the tm_year field is "years since 1900", so be sure to
    add 1900 to the value before trying to print it as YYYY !!

    > and how would i compile it (linking) ?


    No special compilation / linking requirements: use whatever
    method is appropriate to your system to compile and link C programs.
    --
    "No one has the right to destroy another person's belief by
    demanding empirical evidence." -- Ann Landers
     
    Walter Roberson, Aug 25, 2005
    #2
    1. Advertising

  3. placid

    placid Guest

    Walter Roberson wrote:
    > In article <>,
    > placid <> wrote:
    > >how would i get the current date in the format of DD/MM/YYYY, do i use
    > >functions in time.h

    >
    > Yes, use time() to fetch the current time, localtime() to break
    > it down into a struct tm, then extract the structure members of that
    > that you are interested in and print them yourself.
    >
    > Caution: the tm_year field is "years since 1900", so be sure to
    > add 1900 to the value before trying to print it as YYYY !!
    >
    > > and how would i compile it (linking) ?

    >
    > No special compilation / linking requirements: use whatever
    > method is appropriate to your system to compile and link C programs.
    > --
    > "No one has the right to destroy another person's belief by
    > demanding empirical evidence."

    -- Ann Landers


    Thanks man, got it working man
     
    placid, Aug 25, 2005
    #3
  4. In article <dejpcd$cp5$>, -cnrc.gc.ca (Walter Roberson) writes:
    > In article <>,
    > placid <> wrote:
    > >how would i get the current date in the format of DD/MM/YYYY, do i use
    > >functions in time.h

    >
    > Yes, use time() to fetch the current time, localtime() to break
    > it down into a struct tm, then extract the structure members of that
    > that you are interested in and print them yourself.


    Or use strftime:

    #include <time.h>
    #include <stdio.h>
    int main(void)
    {
    time_t Now = time(NULL);
    struct tm Date = *localtime(&Now);
    char DateBuf[12];

    strftime(DateBuf, sizeof DateBuf, "%d/%m/%Y", &Date);
    puts(DateBuf);
    return 0;
    }

    That's what strftime is for.

    --
    Michael Wojcik

    Even if Jesus set up a blogging cafe in the center of Rockport, Texas
    and extolled the virtues of a woman's right to choose while snapping
    pictures of gay weddings with his Nokia, it would have made no
    difference to this election. -- Ashlee Vance
     
    Michael Wojcik, Aug 25, 2005
    #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. Matt
    Replies:
    1
    Views:
    646
    Matthew Speed
    Nov 8, 2003
  2. James P.
    Replies:
    7
    Views:
    12,736
    phamtasmic
    Jul 13, 2004
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,366
    Michael Borgwardt
    May 30, 2004
  4. moonhk
    Replies:
    5
    Views:
    573
    moonhk
    Oct 11, 2006
  5. Michael Haas

    compare date field to current date

    Michael Haas, Feb 15, 2004, in forum: ASP General
    Replies:
    4
    Views:
    301
    Mike Haas
    Feb 15, 2004
Loading...

Share This Page