PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.php > Calendar and date functions
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Calendar and date functions

Réponse
 
LinkBack Outils de la discussion
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
Vieux 04/09/2007, 10h10   #2
Janwillem Borleffs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Calendar and date functions

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
  Réponse avec citation
Vieux 04/09/2007, 11h04   #3
Otis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Calendar and date functions

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

  Réponse avec citation
Vieux 04/09/2007, 12h38   #4
Janwillem Borleffs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Calendar and date functions

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
  Réponse avec citation
Vieux 04/09/2007, 12h49   #5
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Calendar and date functions

..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
  Réponse avec citation
Vieux 04/09/2007, 14h31   #6
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Calendar and date functions

> 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.


  Réponse avec citation
Vieux 04/09/2007, 18h41   #7
Tom
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Calendar and date functions

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

  Réponse avec citation
Vieux 07/09/2007, 00h07   #8
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Calendar and date functions

"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!!!


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h36.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17687 seconds with 16 queries