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 >
Text File  |  1993-01-11  |  2KB  |  73 lines

  1. #include "julian.h"
  2.  
  3. // D A T E _ T O _ J U L
  4. // Converts a string date to a julian date
  5. // 
  6. // date_stp    - the date string to be converted
  7. // format_stp  - the date format (must be the same as date_stp)
  8. //
  9. time_t date_to_jul(char *date_stp,char *format_stp)
  10. {
  11.   char local_date[9];
  12.   struct tm timestruct;
  13.  
  14.   memset(×truct,0,sizeof(struct tm));
  15.   strcpy(local_date,date_stp);
  16.  
  17.   if (strcmp(format_stp,"YY/MM/DD") == 0){
  18.     timestruct.tm_mday = atoi(&local_date[6]);
  19.     local_date[5] = '\0';
  20.     timestruct.tm_mon = atoi(&local_date[3])-1;
  21.     local_date[2] = '\0';
  22.     if (atoi(local_date) < 80)
  23.       timestruct.tm_year = 100+atoi(local_date);
  24.     else
  25.       timestruct.tm_year = atoi(local_date);
  26.   }
  27.   else if (strcmp(format_stp,"MM/DD/YY") == 0){
  28.     if (atoi(&local_date[6]) < 80)
  29.       timestruct.tm_year = 100+atoi(&local_date[6]);
  30.     else
  31.       timestruct.tm_year = atoi(&local_date[6]);
  32.     local_date[5] = '\0';
  33.     timestruct.tm_mday = atoi(&local_date[3]);
  34.     local_date[2] = '\0';
  35.     timestruct.tm_mon = atoi(local_date)-1;
  36.   }
  37.   else if (strcmp(format_stp,"YYMMDD") == 0){
  38.     timestruct.tm_mday = atoi(&local_date[4]);
  39.     local_date[4] = '\0';
  40.     timestruct.tm_mon = atoi(&local_date[2])-1;
  41.     local_date[2] = '\0';
  42.     if (atoi(local_date) < 80)
  43.       timestruct.tm_year = 100+atoi(local_date);
  44.     else
  45.       timestruct.tm_year = atoi(local_date);
  46.   }
  47.   else if (strcmp(format_stp,"YYYYMMDD") == 0){
  48.     timestruct.tm_mday = atoi(&local_date[6]);
  49.     local_date[6] = '\0';
  50.     timestruct.tm_mon = atoi(&local_date[4])-1;
  51.     local_date[4] = '\0';
  52.     if (strncmp(local_date,"20",2) == 0)
  53.       timestruct.tm_year = 100+atoi(&local_date[2]);
  54.     else
  55.       timestruct.tm_year = atoi(&local_date[2]);
  56.   }
  57.   else if (strcmp(format_stp,"MMDDYY") == 0){
  58.     if (atoi(&local_date[4]) < 80)
  59.       timestruct.tm_year = 100+atoi(&local_date[4]);
  60.     else
  61.       timestruct.tm_year = atoi(&local_date[4]);
  62.     local_date[4] = '\0';
  63.     timestruct.tm_mday = atoi(&local_date[2]);
  64.     local_date[2] = '\0';
  65.     timestruct.tm_mon = atoi(local_date)-1;
  66.   }
  67.   else{
  68.     printf("Invalid date picture.\n");
  69.     return(-1L);
  70.   }
  71.   return(mktime(×truct));
  72. }
  73.