|
|
|
#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!!! |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
On Sep 4, 12:38 am, Otis <otie_nos...@cox.net> wrote:
> > PHP is driving me mad with their idiotic way of dealing with > dates and date conversions - unless I'm the idiot. No, you just didn't read the documentation. > 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? $d = "09/03/1951"; $ts = strtotime($d); $year = date('Y', $ts); $month = date('m', $ts); $day = date('d', $ts); > 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. You are mistaken. PHP wants to deal with timestamps. Cheers, NC |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
Thank you for your (civil) reply.
Yes, I finally figured out about the timestamps. But I must tell you that the PHP documentation for date stuff stinks. Who needs silly examples on how to get current date and time? Those examples are worthless, practically speaking. There are few or no examples of how to do things with different dates other than current dates. On this issue, VB documentation beats the heck out of PHP documentation. I have several books on PHP and they all do a lousy job when talking about dates and times. They must think that the real world only deals with current dates and times. Very poor. But with your and JW's, it lead me to the apparent right solution. Thank you. Otis NC wrote: > On Sep 4, 12:38 am, Otis <otie_nos...@cox.net> wrote: >> PHP is driving me mad with their idiotic way of dealing with >> dates and date conversions - unless I'm the idiot. > > No, you just didn't read the documentation. > >> 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? > > $d = "09/03/1951"; > $ts = strtotime($d); > $year = date('Y', $ts); > $month = date('m', $ts); > $day = date('d', $ts); > >> 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. > > You are mistaken. PHP wants to deal with timestamps. > > Cheers, > NC > |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
..oO(Otis)
>Thank you for your (civil) reply. > >Yes, I finally figured out about the timestamps. > >But I must tell you that the PHP documentation for date stuff stinks. Not really. >Who needs silly examples on how to get current date and time? Those >examples are worthless, practically speaking. There are few or no >examples of how to do things with different dates other than current >dates. For many date functions, especially the formatting functions, it doesn't really matter if they're used with the current or another date. >On this issue, VB documentation beats the heck out of PHP >documentation. I have several books on PHP and they all do a lousy job >when talking about dates and times. What did you expect? Micha |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
> Thank you for your (civil) reply.
don't start bashing the namesake of this ng and expect a civil reply. > But I must tell you that the PHP documentation for date stuff stinks. oh, so now it's PHP DOCUMENTATION that's at fault. > Who needs silly examples on how to get current date and time? Those > examples are worthless, practically speaking. There are few or no examples > of how to do things with different dates other than current dates. even if you had a point here (which you don't), have you ever heard of google?!! >On this issue, VB documentation beats the heck out of PHP documentation. for christ's sake!!! THEN USE VB, dipshit! i bet you're still using vb classic and relying on rick or karl or another mvp to give you the answers to your inane questions (that you STILL fail to RTFM for yourself). i pitty the vb.net ng when you decide you think you can handle the .net change! >I have several books on PHP and they all do a lousy job when talking about >dates and times. They must think that the real world only deals with >current dates and times. Very poor. you're a freaking MORON!!! google! date() is so simple, with the internet littered with examples, that putting most of them in the .chm is a waste of time...though more expanded examples of its use are right there in php.net's documentation!!! > But with your and JW's, it lead me to the apparent right solution. oh, so the example (repeated here by NC almost verbatim) i posted a fucking week ago did nothing for you. ROFLMFAO! > Thank you. again, piss off goof-ball. |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
On Sep 10, 12:05 am, Otis <otie_nos...@cox.net> wrote:
> > I must tell you that the PHP documentation for date > stuff stinks. I disagree. Just look at documentation for date(): date (PHP 4, PHP 5) date -- Format a local time/date Description string date ( string $format [, int $timestamp] ) Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given. In other words, timestamp is optional and defaults to the value of time(). http://www.php.net/date > Who needs silly examples on how to get current date > and time? All you needed to do is to carefully read the first paragraph; it had all the information you needed... Cheers, NC |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
I guess my big problem when all is said and done was I didn't really
understand the concept/meaning of "timestamp" and all it entailed. Thank you for your . Otis NC wrote: > On Sep 10, 12:05 am, Otis <otie_nos...@cox.net> wrote: >> I must tell you that the PHP documentation for date >> stuff stinks. > > I disagree. Just look at documentation for date(): > > date > > (PHP 4, PHP 5) > > date -- Format a local time/date > Description > string date ( string $format [, int $timestamp] ) > > Returns a string formatted according to the given format > string using the given integer timestamp or the current > time if no timestamp is given. In other words, timestamp > is optional and defaults to the value of time(). > > http://www.php.net/date > >> Who needs silly examples on how to get current date >> and time? > > All you needed to do is to carefully read the first paragraph; it had > all the information you needed... > > Cheers, > NC > |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
>I guess my big problem
so many that you have to specify categorically of which one you speak... > when all is said and done was I didn't really understand the > concept/meaning of "timestamp" and all it entailed. don't read much, eh? > Thank you for your . thanks would be for you to have learned in this thread how to ask questions that don't expose your ignorance, such as: what is the php equivalent to visual basic's year(), day(), month() functions? rather than how you sophomorically posed your op. |
|
![]() |
| Outils de la discussion | |
|
|