[ciapug] Date Conversion
Bryan Baker
bbaker at iowalaw.org
Thu Dec 22 11:56:55 CST 2005
Sounds like you've tripped over a UNIX epoch issue.
On Dec 22, 2005, at 11:45 AM, Dave J. Hala Jr. wrote:
> I found a little nasty in this code. For some reason, dates older than
> 1970 don't work. Anyone got any ideas?
>
> if $date= '1970-01-01' and $type='9' the result is ok. However
> $date=1969-01-01' and $type='9' returns "December 31st, 1969"
>
>
> function date_convert($date,$type){
> #echo "FC: date_convert: $date <BR> ";
> $date_year=substr($date,0,4);
> $date_month=substr($date,5,2);
> $date_day=substr($date,8,2);
>
> if($type == 1):
> // Returns the year Ex: 2003
> $date=date("Y", mktime(0,0,0,$date_month,$date_day,$date_year));
> elseif($type == 2):
> // Returns the month Ex: January
> $date=date("F", mktime(0,0,0,$date_month,$date_day,$date_year));
> elseif($type == 3):
> // Returns the short form of month Ex: Jan
> $date=date("M", mktime(0,0,0,$date_month,$date_day,$date_year));
> elseif($type == 4):
> // Returns numerical representation of month with leading zero Ex:
> Jan = 01, Feb = 02
> $date=date("m", mktime(0,0,0,$date_month,$date_day,$date_year));
> elseif($type == 5):
> // Returns numerical representation of month without leading zero
> Ex:
> Jan = 1, Feb = 2
> $date=date("n", mktime(0,0,0,$date_month,$date_day,$date_year));
> elseif($type == 6):
> // Returns the day of the week Ex: Monday
> $date=date("l", mktime(0,0,0,$date_month,$date_day,$date_year));
> elseif($type == 7):
> // Returns the day of the week in short form Ex: Mon, Tue
> $date=date("D", mktime(0,0,0,$date_month,$date_day,$date_year));
> elseif($type == 8):
> // Returns a combo ExL Wed,Nov 12th,2003
> $date=date("D, M jS, Y",
> mktime(0,0,0,$date_month,$date_day,$date_year));
> elseif($type == 9):
> // Returns a combo Ex: November 12th,2003
> $date=date("F jS, Y",
> mktime(0,0,0,$date_month,$date_day,$date_year));
> elseif($type == 10):
> // Returns a combo ExL Wednesday, November 12th,2003
> $date=date("l, F jS, Y",
> mktime(0,0,0,$date_month,$date_day,$date_year));
>
> endif;
> return ($date);
> };
>
> --
>
> Open Source Information Systems, Inc. (OSIS)
> Dave J. Hala Jr., President <dave at osis.us>
> 641.485.1606
>
> _______________________________________________
> ciapug mailing list
> ciapug at cialug.org
> http://cialug.org/mailman/listinfo/ciapug
>
>
--
Bryan Baker
Technology Advocate
Iowa Legal Aid
Suite 230
1111 9th Street
Des Moines, Ia 50314-2527
(515) 243-2151 (x1635)
http://www.iowalegalaid.org
bbaker at iowalaw.org
More information about the ciapug
mailing list