Dec 6, 2002 #1 Plato2 Programmer Dec 6, 2002 192 US E.g. I ahve the following: char time[20]; time="12/06/02"; How can I convert to date this string? Thanks in advance!
E.g. I ahve the following: char time[20]; time="12/06/02"; How can I convert to date this string? Thanks in advance!
Dec 7, 2002 #2 victorv Vendor Aug 20, 2002 862 IT hi, if with "date" you mean time_t C standard type to manage date/time, you can use the mktime function. char in_date[20]="12/06/02"; struct tm TM ; int M,D,Y; char buf[3]; memset( &TM, 0, sizeof(TM) ); memset( buf, 0, 3 ); memcpy( buf, in_date+0, 2 ); M = atoi( buf ) ; memcpy( buf, in_date+3, 2 ); D = atoi( buf ) ; memcpy( buf, in_date+6, 2 ); Y = atoi( buf ) ; TM.tm_mday = D ; // Day of the month - [1,31] TM.tm_mon = M-1 ; // Months since January - [0,11] TM.tm_year = D+100 ; // Years since 1900 return mktime( &TM ) ; BYE Upvote 0 Downvote
hi, if with "date" you mean time_t C standard type to manage date/time, you can use the mktime function. char in_date[20]="12/06/02"; struct tm TM ; int M,D,Y; char buf[3]; memset( &TM, 0, sizeof(TM) ); memset( buf, 0, 3 ); memcpy( buf, in_date+0, 2 ); M = atoi( buf ) ; memcpy( buf, in_date+3, 2 ); D = atoi( buf ) ; memcpy( buf, in_date+6, 2 ); Y = atoi( buf ) ; TM.tm_mday = D ; // Day of the month - [1,31] TM.tm_mon = M-1 ; // Months since January - [0,11] TM.tm_year = D+100 ; // Years since 1900 return mktime( &TM ) ; BYE