I have a date in the format of YYYY-MM-DD as a string (including the hyphens)

How do I split this string just to obtain YYYY, MM and DD separately? Possible use of an array or something?

Would really appreciate some help :)

Edit: Nevermind, just discovered the explode() function :P

Use index and rindex functions as given here and a little string handling can serve your purpose.

#define ERROR(X) printf("%s Failed\n", X)


int main()
{

	char *month;
	char *year;
	char *date = "dd-mm-yy";

	month = index(date, '-');
	if (month == NULL)
		ERROR("index");
	
	year = rindex(date, '-');
	if(year == NULL)
		ERROR("rindex");

	printf("date = %s month = %s yeat = %s\n", date, month, year);
	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.