paulspoon Posted July 13, 2006 Share Posted July 13, 2006 I've got a text field with the following value "20060710" and want to convert it to look like this "2005/07/10".All help appreciated Quote Link to comment https://forums.phpfreaks.com/topic/14454-date-format-help/ Share on other sites More sharing options...
brown2005 Posted July 13, 2006 Share Posted July 13, 2006 post some code on how you got the date please Quote Link to comment https://forums.phpfreaks.com/topic/14454-date-format-help/#findComment-57156 Share on other sites More sharing options...
CheesierAngel Posted July 13, 2006 Share Posted July 13, 2006 I suppose the date is not generated but inputted by the costumers. You could use:[code]<?php $notGood = "20060710"; $match = array(); if(preg_match('/^([0-9]){4}([0-9]){2}([0-9]){2})/', $notGood, $match)) { $good = $match[0] . "/" . $match[1] . "/" . $match[2]; } echo notGood . " - " . $good;?>[/code]Or you could use following aswell:[code]<?php $notGood = "20060710"; $match = array(); if(preg_match('/^([0-9]){4}([0-9]){2}([0-9]){2})/', $notGood, $match)) { $good = date('YYYY/m/d', mktime('', '', '', $match[1], $match[2], $match[0])); } echo $good;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14454-date-format-help/#findComment-57157 Share on other sites More sharing options...
paulspoon Posted July 13, 2006 Author Share Posted July 13, 2006 Doesn't work ?Parse error: syntax error, unexpected '[' in /Data/www/dev.chaplease help Quote Link to comment https://forums.phpfreaks.com/topic/14454-date-format-help/#findComment-57169 Share on other sites More sharing options...
CheesierAngel Posted July 13, 2006 Share Posted July 13, 2006 You can change it to [code]<?php if(preg_match('/^(\d){4}(\d){2}(\d){2}/', $notGood, $match)) { .... }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14454-date-format-help/#findComment-57172 Share on other sites More sharing options...
paulspoon Posted July 13, 2006 Author Share Posted July 13, 2006 Still nothing , next errorParse error: syntax error, unexpected T_STRING in /Data/www/dev.chaSorry for the inconvinience Quote Link to comment https://forums.phpfreaks.com/topic/14454-date-format-help/#findComment-57174 Share on other sites More sharing options...
CheesierAngel Posted July 13, 2006 Share Posted July 13, 2006 Just tested it and is working:[code]<?php $notGood = "20060710"; $match = array(); $good = ""; if(preg_match('/^([0-9]){4}([0-9]){2}([0-9]){2}/', $notGood, $match)) { $good = date('Y/m/d', mktime('', '', '', $match[1], $match[2], $match[0])); } echo $good;?>[/code]Also working:[code]<?php $notGood = "20060710"; $match = array(); if(preg_match('/^([0-9]){4}([0-9]){2}([0-9]){2}/', $notGood, $match)) { $good = $match[0] . "/" . $match[1] . "/" . $match[2]; } echo $notGood . " - " . $good;?>[/code]Sorry, was forgotten some $ signs and had a ) sign too much in. Quote Link to comment https://forums.phpfreaks.com/topic/14454-date-format-help/#findComment-57179 Share on other sites More sharing options...
BillyBoB Posted July 13, 2006 Share Posted July 13, 2006 $datefromdb = $sominhere['time_data'];$year = substr($datefromdb,0,4);$mon = substr($datefromdb,4,2);$day = substr($datefromdb,6,2);$hour = substr($datefromdb,8,2);$min = substr($datefromdb,10,2);$sec = substr($datefromdb,12,2);$orgdate = date("l F dS, Y h:i A",mktime($hour,$min,$sec,$mon,$day,$year));?>Date: <? echo $orgdate; ?> Quote Link to comment https://forums.phpfreaks.com/topic/14454-date-format-help/#findComment-57180 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.