confused about sprintf

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?

Every string has to terminated with a null - '\0'. That's probably why the first example has 17 elements - 16 characters and one null. So you need to declare time and date as 9 bytes.

The first code is wrong as well, array size should be 18.

guix:
The first code is wrong as well, array size should be 18.

Yes, because the space character between date and time adds one.

thanks got it solved just increased the array sizes and it got it in order