Date reading in C...

Bruce R. Williams bwilliam%peruvian.utah.edu at cs.utah.edu
Mon Feb 4 16:48:45 AEST 1991


In article <1991Feb2.193758.7570 at cs.dal.ca> dinn at ug.cs.dal.ca (Michael Dinn) writes:
>I need some C code that will give me the variables month, day and year
>as being set to the current month day and year. (time would be
>nce as well as the date...)
>
> Examples of any sort would be welcomed...

This is a very system-specific question.  Here is an example using
Turbo C 2.0 on an AT:

-Bruce

------------------
/* Retrieve and display the system date */
/* Written by Bruce R. Williams */

#include <stdio.h>
#include <dos.h>

main()
{
    struct date dt;
    char *month[] = {"January", "February", "March", "April", "May",
		    "June", "July", "August", "September", "October",
		    "November", "December"};

    getdate(&dt);
    printf("Today is %s %d, %d\n",month[dt.da_mon - 1],dt.da_day,dt.da_year);
}
Bruce R. Williams                "The most beautiful thing we can experience
University of Utah                is the mysterious.  It is the source of all
(bwilliam at peruvian.utah.edu)      true art and science."  -Albert Einstein



More information about the Comp.lang.c mailing list