I have a sample code for a DS1338 RTC that I got from www.hobbytronics.co.uk. In a function to read the RTC there is the following line
char datetime[17]
........
//print the date EG DD/MM/YY HH:MM:SS
sprintf(datetime,"%2.2d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d", monthDay, month, year, hour, minute, second);
and that works fine, but I need to change it from one character array containing the formatted date and time into two character array's, one for date and one for time so I thought it was as simple as this
char date[8];
char time[8];
........
sprintf(date,"%2.2d-%2.2d-%2.2d", month, monthDay, year);
sprintf(time,"%2.2d:%2.2d:%2.2d", hour, minute, second);
but instead of getting date in one variable and time in another I get
05-12-1517:35:56
17:35:56
if I change my code to the following I do get the date all by itself, but of course I am not storing the time in a variable anymore
char date[8];
char time[8];
........
sprintf(date,"%2.2d-%2.2d-%2.2d", month, monthDay, year);
//sprintf(time,"%2.2d:%2.2d:%2.2d", hour, minute, second);
I am sure I am missing something simple, any thoughts?