Afficher un message
Vieux 04/09/2007, 08h38   #1
Otis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Calendar and date functions

PHP is driving me mad with their idiotic way of dealing with dates and
date conversions - unless I'm the idiot.

Here's what I need:

Let's assume the date is $d = "09/03/1951" - Sep 3, 1951

How do I get just the year from a date like Sep 3, 1951?
How do I get just the day from a date like Sep 3, 1951?
How do I get just the month from a date like Sep 3, 1951?

I have never been able to get PHP to deal properly with the years since
it seems to have the stupid habit of deciding for itself whether a year
is 2000 something or 1900 something. It apparently only wants to deal
with 2-digit years.

Here is what I have done in the past when I needed a FULL date:

if ($inyear >= 2000)
{
$utdatenow = strftime("%d.%m.20%y", mktime($inhours, $inmins,
$insecs, $inmonth, $inday, $inyear));
}
else
{
$utdatenow = strftime("%d.%m.19%y", mktime($inhours, $inmins,
$insecs, $inmonth, $inday, $inyear));
}

How cumbersome!!!

Isn't PHP/UNIX smart enough to know what the 4-digit year is without me
having to jump through hoops?

In Visual Basic it was simple:

yr$ = Year("09/03/1951") gave me 1951
dy$ = Day("09/03/1951") gave me 3
mo$ = Month("09/03/1951") gave me 9

Why isn't PHP as straight-forward?


Thank you.


Otis
  Réponse avec citation
 
Page generated in 0,06384 seconds with 9 queries