Jump to content

Stripping Date


smerny

Recommended Posts

$birthdate is in the format of YYYY-MM-DD

	$byear = strtok($birthdate, "-");	$bmonth = strtok("-");	$bday = strtok("-");

I was thinking this would work based on the w3 tutorial which says:

<?php$string = "Hello world. Beautiful day today.";$token = strtok($string, " ");while ($token != false)  {  echo "$token<br />";  $token = strtok(" ");  } ?>

The output of the code above will be:Helloworld.Beautifuldaytoday.

I am getting null values, what am I doing wrong?
Link to comment
Share on other sites

Is $birthdate a string? Does $birthdate have a value? Or is it empty?Just tried the code below and it works like a charm..

$birthdate = "2009-06-06";	$byear = strtok($birthdate, "-");	$bmonth = strtok("-");	$bday = strtok("-");		echo "Year: $byear<br />";	echo "Month: $bmonth<br />";	echo "Day: $bday";

Check and see what format $birthdate is being stored in.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...