How do I parse a date string into its components

  • Questions
  • How do I parse a date string into its components
Question ID: 105100
1
0

I have a data value return as a date like this: 08082013121536

Using C code, how do I break this into the following:
Month = 08
Day = 08
Year = 2013
Hour = 12
Min = 15
Sec = 36

Can someone please provide the code to do this.

Marked as spam
Posted by (Questions: 23, Answers: 4)
Asked on August 12, 2013 5:04 pm
3 views
Answers (1)
2
Private answer

Action()
{
/* Example:
String = ''08082013121536''
This string represents a timestamp, as you can likely tell. The value of this will vary widely (as expected)
I'd like to ''break up'' this string into its respective pieces (and corresponding variables)...
Month = 08
Day = 08
Year = 2012
Hour = 12
Min = 15
Sec = 36
*/

char * DString = ''08082013121536'';
char Month[3], Day[3], Year[5], Hour[3], Min[3], Sec[3];

strncpy(Month, DString, 2);
strncpy(Day, DString+2, 2);
strncpy(Year, DString+4, 4);
strncpy(Hour, DString+8, 2);
strncpy(Min, DString+10, 2);
strncpy(Sec, DString+12, 2);

lr_message(''Month = %s, Day = %s, Year = %s, Hour = %s, Min= %s, Sec = %s'',
Month,
Day,
Year,
Hour,
Min,
Sec);

return 0;
}

Marked as spam
Posted by (Questions: 17, Answers: 252)
Answered on August 12, 2013 5:59 pm