0

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

Edited by ElegantElephant: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by csmgsarma
-1

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;
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.