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
Vieux 10/09/2007, 00h01   #9
NC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Calendar and date functions

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

  Réponse avec citation
Vieux 10/09/2007, 08h05   #10
Otis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Calendar and date functions

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
>

  Réponse avec citation
Vieux 10/09/2007, 14h57   #11
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Calendar and date functions

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

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


  Réponse avec citation
Vieux 11/09/2007, 01h37   #13
NC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Calendar and date functions

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

  Réponse avec citation
Vieux 11/09/2007, 03h29   #14
Otis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Calendar and date functions

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
>

  Réponse avec citation
Vieux 11/09/2007, 14h03   #15
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Calendar and date functions

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


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


É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,21350 seconds with 23 queries