Does Anybody Know How I Could Get The Date (In Short Format)

This is a discussion on Does Anybody Know How I Could Get The Date (In Short Format) within the C Programming forums, part of the General Programming Boards category; Does Anybody Know How I Could Get The Date (In Short Format)...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    6

    Does Anybody Know How I Could Get The Date (In Short Format)

    Does Anybody Know How I Could Get The Date (In Short Format)

  2. #2
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    You can get the current time with time(), convert it to a tm structure with either gmtime() or localtime() and get a formatted string with strftime() from the tm structure.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    41
    Code:
    #include <stdio.h>
    #include <time.h>
    
    main() {
            char date_Ymd[8+1];
            struct tm *gsapdh;
            time_t gsaintps;
            gsaintps=time(NULL);
            gsapdh = localtime(&gsaintps);
            strftime(date_Ymd, 9, "%Y%m%d", gsapdh);
    
            printf("Date_Ymd: [%s]\n",date_Ymd);
    
    }
    You can format as ever you wish.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Don't forget,

    Code:
    int main() {
    Try ctime().

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    6
    Hey Groorj
    Thanx man, really appreciate that easy to understand, and was pretty useful for my assignment, cheers buddy :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. unable to recieve UDP packet
    By caroundw5h in forum Networking/Device Communication
    Replies: 15
    Last Post: 09-19-2007, 11:11 AM
  2. Compiler/Class bug?
    By Blackroot in forum C++ Programming
    Replies: 2
    Last Post: 01-31-2006, 10:56 PM
  3. validating a date month and year format
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 08-16-2005, 07:45 AM
  4. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 04:23 PM
  5. Date class help!! Please
    By C++Newbie in forum C++ Programming
    Replies: 3
    Last Post: 11-12-2001, 12:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21