Jump to content

Getting parts of a record


Guest FirefoxRocks
 Share

Recommended Posts

Guest FirefoxRocks

Originally posted at http://www.astahost.com/getting-certain-pa...ord-t17148.html.

Ok I need help on this puzzling problem. At first I thought that this person stored the dates in the MySQL database like this:August 27, 2007That kinda freaked me out a little, because string dates are hard to manipulate. Then I found out that he stored both th string data and numerical date, which I found a little bit odd, but it was like this:2007-08-27I need to build a PHP program to manipulate the data, but I need to access the year, month and day respectively by themselves.I think that isolating the first 4 characters for the year, last 2 characters for day and 6th and 7th characters for month would be the easiest method to do this. Then I could pass the data onto an XML file, in then which I will use XSLT to transform the data. So how do I do that? (I already got the XML/XSLT part, but I need help on the initial problem.)
I think that a lot of people here (especially boen_robot) can help me with this. What do you think?
Link to comment
Share on other sites

Use explode to break the date into pieces.http://www.php.net/manual/en/function.explode.phpYou can split the first date on spaces and the the last date on the dash. For the first date, you can use intval on the middle number to keep the number and strip any other characters (like the comma, or a "th" or whatever else).http://www.php.net/manual/en/function.intval.phpYou can have a switch statement for the month name to choose which number it is.http://www.php.net/manual/en/control-structures.switch.phpOnce you have the parts you can use mktime to convert it to a date and do whatever else you want with it.http://www.php.net/manual/en/function.mktime.phpYou didn't really say what the final goal was, but you can probably make it from there. Check the date/time reference on php.net for more information.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...