Im writing a code to generate invoice numbers. Im using a file now that increment to number each time but i was just wondering if there is a way to use time so that it can generate a invoice using time or date. Like the first 4 digit would give the date and month or something like that. Can that be done and would someone give me a few tips on how to make that code

5 Years
Discussion Span
Last Post by fpsasm

http://rabbit.eng.miami.edu/info/functions/time.html#localtime :

tm * localtime(time_t * tim)
tm * gmtime(time_t * tim)
tm * localtime_r(time_t * tim, tm * output)
tm * gmtime_r(time_t * tim, tm * output)
struct tm * localtime(time_t * tim) in C
struct tm * gmtime(time_t * tim) in C
struct tm * localtime_r(time_t * tim, struct tm * output) in C
struct tm * gmtime_r(time_t * tim, struct tm * output) in C
include: <time.h>
The parameter is a pointer to a time_t (effectively an int) variable containing
the time in seconds since 1/1/1970. The represented time is analysed to produce
all the components: hour, minute, second, day, month, year, day-of-week, time zone.
Those values are stored in a tm structure, and a pointer to that structure is
returned. All calls to localtime and gmtime use the same static structure, so
each call overwrites the results of the previous call.
Localtime uses the local time zone, gmtime converts to GMT (or UTC).
Localtime_r and gmtime_r are exactly the same as localtime and gmtime, except
that the caller must provide a pointer to an existing tm object, and the components
of that object will be filled in; the return result is the same as the second parameter.
time_t values are produced from the clock by time.
tm structures are converted to strings by asctime.

time_t tim=time(NULL);
             tm *now=localtime(&tim);
             printf("Date is %d/%02d/%02d\n", now->tm_year+1900, now->tm_mon+1, now->tm_mday);
             printf("Time is %02d:%02d\n", now->tm_hour, now->tm_min);

Rather then printing a date, you would store it into a string.. and then use that (string) for your file-name

Edited by fpsasm: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.