home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
j
/
julian11.zip
/
DATEJTO.C
< prev
next >
Wrap
Text File
|
1993-01-11
|
2KB
|
73 lines
#include "julian.h"
// D A T E _ T O _ J U L
// Converts a string date to a julian date
//
// date_stp - the date string to be converted
// format_stp - the date format (must be the same as date_stp)
//
time_t date_to_jul(char *date_stp,char *format_stp)
{
char local_date[9];
struct tm timestruct;
memset(×truct,0,sizeof(struct tm));
strcpy(local_date,date_stp);
if (strcmp(format_stp,"YY/MM/DD") == 0){
timestruct.tm_mday = atoi(&local_date[6]);
local_date[5] = '\0';
timestruct.tm_mon = atoi(&local_date[3])-1;
local_date[2] = '\0';
if (atoi(local_date) < 80)
timestruct.tm_year = 100+atoi(local_date);
else
timestruct.tm_year = atoi(local_date);
}
else if (strcmp(format_stp,"MM/DD/YY") == 0){
if (atoi(&local_date[6]) < 80)
timestruct.tm_year = 100+atoi(&local_date[6]);
else
timestruct.tm_year = atoi(&local_date[6]);
local_date[5] = '\0';
timestruct.tm_mday = atoi(&local_date[3]);
local_date[2] = '\0';
timestruct.tm_mon = atoi(local_date)-1;
}
else if (strcmp(format_stp,"YYMMDD") == 0){
timestruct.tm_mday = atoi(&local_date[4]);
local_date[4] = '\0';
timestruct.tm_mon = atoi(&local_date[2])-1;
local_date[2] = '\0';
if (atoi(local_date) < 80)
timestruct.tm_year = 100+atoi(local_date);
else
timestruct.tm_year = atoi(local_date);
}
else if (strcmp(format_stp,"YYYYMMDD") == 0){
timestruct.tm_mday = atoi(&local_date[6]);
local_date[6] = '\0';
timestruct.tm_mon = atoi(&local_date[4])-1;
local_date[4] = '\0';
if (strncmp(local_date,"20",2) == 0)
timestruct.tm_year = 100+atoi(&local_date[2]);
else
timestruct.tm_year = atoi(&local_date[2]);
}
else if (strcmp(format_stp,"MMDDYY") == 0){
if (atoi(&local_date[4]) < 80)
timestruct.tm_year = 100+atoi(&local_date[4]);
else
timestruct.tm_year = atoi(&local_date[4]);
local_date[4] = '\0';
timestruct.tm_mday = atoi(&local_date[2]);
local_date[2] = '\0';
timestruct.tm_mon = atoi(local_date)-1;
}
else{
printf("Invalid date picture.\n");
return(-1L);
}
return(mktime(×truct));
}