Getting the system date

This is a discussion on Getting the system date within the C Programming forums, part of the General Programming Boards category; Hi, Using C on Unix, how can I get the current date (day, month, year)? Thanks, arthur....

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    2

    Smile Getting the system date

    Hi,

    Using C on Unix, how can I get the current date (day, month, year)?

    Thanks,
    arthur.

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    2

    Smile Date

    Hmm,

    Even after reading that tutorial I don't quite understand. I'm not very familiar with structs.

    How can I just get the month, day, and year into int or string variables?

    Thanks,
    arthur.

  4. #4
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125
    Quote Originally Posted by bboy_vitasoy
    Hmm,

    Even after reading that tutorial I don't quite understand. I'm not very familiar with structs.

    How can I just get the month, day, and year into int or string variables?

    Thanks,
    arthur.

    Then get familiar with them. You're not going to get very far in any kind of serious C programming without learning about structs. Good structure info begins on page 127 of the ANSI C edition of K&R, or google "C structs tutorial" and learn about them.

    In the FAQ there is an example of what you need to do: basically get the time now using the time() function -- this gives you the number "epoch seconds" -- seconds since the start of the Epoch (1970-01-01). Then feed that time value to localtime, which returns a time struct.

    Pick and choose the values you want out of that. Then copy them into the strings, making sure you allocate enough space.
    Mr. Blonde: You ever listen to K-Billy's "Super Sounds of the Seventies" weekend? It's my personal favorite.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. calculate age from date
    By bazzano in forum C Programming
    Replies: 1
    Last Post: 08-22-2005, 09:57 AM
  2. Getting system Date
    By Sridar in forum C++ Programming
    Replies: 4
    Last Post: 08-10-2005, 09:51 PM
  3. bad system date
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 04-30-2003, 09:29 AM
  4. reading the system date
    By Alicia in forum C++ Programming
    Replies: 5
    Last Post: 02-13-2002, 03:18 PM
  5. System Date
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 08-28-2001, 07:03 PM

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