Does anyone know how to change 11841 to 1941-11-08. I have this date format coming out a old system that I need to change. Thanks in advance for any help.
[RESOLVED] change date format
Basically it is impossible to decode all the dates in that format. As an example, what date is 11197? Is it year 1997, month 11, day 1 or is it year 1997, month 1, day 11?
But if you can solve that problem you should be able to use the [man]date[/man] function to create the date and the [man]substr[/man] function to get the values from the old date.
11197 would be 1997-01-11, and 110197 would be 1997-11-01, so how would I decode that.
// assume $oldDate has the original value:
preg_match('/(\d{1,2})(\d\d)(\d\d)/', $oldDate, $dateParts);
$newDate = sprintf('%04d-%02d-%02d', $dateParts[3], $dateParts[1], $dateParts[2]);
That seems to work great, just missing one thing. The output comes out as 0048-01-23, when it should be 1948-01-23, where do I change that at.
Change %04d to 19%02d.
raouleduke wrote:That seems to work great, just missing one thing. The output comes out as 0048-01-23, when it should be 1948-01-23, where do I change that at.
If it's always going to be 19xx, then just change the sprintf() to:
$newDate = sprintf('19%02d-%02d-%02d', $dateParts[3], $dateParts[1], $dateParts[2]);
Yep, I got that, thanks for helping me out.
Yup ^
Lol NogDog, you're the first result on google for "misery wrapped in enema". You should be proud.
madwormer2 wrote:Yup ^
Lol NogDog, you're the first result on google for "misery wrapped in enema". You should be proud.
Story of my life.