By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

current date

P: n/a
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) ?

Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <11**********************@g47g2000cwa.googlegroups .com>,
placid <Bu****@gmail.com> 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
Nov 15 '05 #2

P: n/a

Walter Roberson wrote:
In article <11**********************@g47g2000cwa.googlegroups .com>,
placid <Bu****@gmail.com> 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

Nov 15 '05 #3

P: n/a

In article <de**********@canopus.cc.umanitoba.ca>, ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
In article <11**********************@g47g2000cwa.googlegroups .com>,
placid <Bu****@gmail.com> 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 mi************@microfocus.com

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
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.