Guest FirefoxRocks Posted October 17, 2007 Share Posted October 17, 2007 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 More sharing options...
justsomeguy Posted October 17, 2007 Share Posted October 17, 2007 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 More sharing options...
Guest FirefoxRocks Posted October 17, 2007 Share Posted October 17, 2007 I think that the method suggested in the Astahost is much easier, don't you think? [see quoted link for more details] Link to comment Share on other sites More sharing options...
justsomeguy Posted October 17, 2007 Share Posted October 17, 2007 That will work for the numeric format, for the text format you need to use the switch as far as I know. Unless someone knows otherwise. Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted October 17, 2007 Share Posted October 17, 2007 I am using XSLT to convert to text format. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 17, 2007 Share Posted October 17, 2007 Sounds like you've got your problem solved then. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.