|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Otis schreef:
> 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? > Use the calendar extension: http://www.php.net/calendar JW |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
These don't me with the problems I described.
otis Janwillem Borleffs wrote: > Otis schreef: >> 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? >> > > Use the calendar extension: > > http://www.php.net/calendar > > > JW |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Otis schreef:
> These don't me with the problems I described. > $d = 'Sep 3, 1951'; $y = strftime('%Y', strtotime($d)); $m = strftime('%m', strtotime($d)); $d = strftime('%d', strtotime($d)); JW |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
..oO(Otis)
>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? Internally PHP works with Unix timestamps. Use strtotime() to turn your date into such a timestamp, then use whatever date function you like, e.g. $date = getdate(strtotime('09/03/1951')); Now $date will be an array with all the informations you want: Array ( [seconds] => 0 [minutes] => 0 [hours] => 0 [mday] => 3 [wday] => 1 [mon] => 9 [year] => 1951 [yday] => 245 [weekday] => Monday [month] => September [0] => -578451600 ) Micha |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
> unless I'm the idiot.
which is totally the case. don't bash php because *you* don't get it. rtfm! > Here's what I need: > > Let's assume the date is $d = "09/03/1951" - Sep 3, 1951 $d = strtotime('09/03/1951'); // which won't work on windows server > How do I get just the year from a date like Sep 3, 1951? echo date('Y', $d); > How do I get just the day from a date like Sep 3, 1951? echo date('d', $d); > How do I get just the month from a date like Sep 3, 1951? echo date('m'); really hard, ain't it?!!! > 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. ALL software languages have to ASSUME what year you want when you give it a two-digit year, moron! AND MOST ALL OF THEM use 38 as the magic number. if below or eq 38, 20 + two-digit is used...if > 38, 19 + two-digit. RTFM !!! > 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!!! yep...never mind it being stupid. > Isn't PHP/UNIX smart enough to know what the 4-digit year is without me > having to jump through hoops? lol...aren't you smart enough to read a fucking manual? > In Visual Basic it was simple: ahhhh...NOW THAT EXPLAINS IT!!! > 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? it is, AND it is *easier* because you only need ONE function in the first place in order to get the result(s) you want! > Thank you. piss off. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On Tue, 04 Sep 2007 00:38:22 -0700, Otis wrote...
> >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 Might check either of there at the PHP site. I believe the top one will give you a string of text with the information you request. The second would give you an array you can probably get more use out of... http://www.php.net/manual/en/function.date.php http://www.php.net/manual/en/function.getdate.php Tom -- NewsGuy Takes Usenet Cellular! Download newsgroup MP3's to your Cell or PDA Free Trial - http://newsguy.com/cellphone.htm |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
"Otis" <otie_nospam@cox.net> wrote in message
news:r5aDi.86468$Mu5.80898@newsfe15.phx... > These don't me with the problems I described. > > > otis dude! pull your head out of your ass!!! |
|
![]() |
| Outils de la discussion | |
|
|