Calendar and date functions

Calendar and date functions

am 04.09.2007 09:38:22 von 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?

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

Re: Calendar and date functions

am 04.09.2007 11:10:32 von Janwillem Borleffs

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

Re: Calendar and date functions

am 04.09.2007 12:04:54 von Otis

These don't help 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

Re: Calendar and date functions

am 04.09.2007 13:38:31 von Janwillem Borleffs

Otis schreef:
> These don't help 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

Re: Calendar and date functions

am 04.09.2007 13:49:47 von Michael Fesser

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

Re: Calendar and date functions

am 04.09.2007 15:31:13 von Steve

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

Re: Calendar and date functions

am 04.09.2007 19:41:16 von unknown

Post removed (X-No-Archive: yes)

Re: Calendar and date functions

am 07.09.2007 01:07:23 von Steve

"Otis" wrote in message
news:r5aDi.86468$Mu5.80898@newsfe15.phx...
> These don't help me with the problems I described.
>
>
> otis

dude! pull your head out of your ass!!!

Re: Calendar and date functions

am 10.09.2007 01:01:56 von nc

On Sep 4, 12:38 am, Otis 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

Re: Calendar and date functions

am 10.09.2007 09:05:15 von 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.
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 help and JW's, it lead me to the apparent right solution.

Thank you.



Otis


NC wrote:
> On Sep 4, 12:38 am, Otis 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
>

Re: Calendar and date functions

am 10.09.2007 15:57:44 von Michael Fesser

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

Re: Calendar and date functions

am 10.09.2007 18:49:16 von Steve

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

Re: Calendar and date functions

am 11.09.2007 02:37:14 von nc

On Sep 10, 12:05 am, Otis 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

Re: Calendar and date functions

am 11.09.2007 04:29:59 von Otis

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



Otis


NC wrote:
> On Sep 10, 12:05 am, Otis 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
>

Re: Calendar and date functions

am 11.09.2007 15:03:48 von Steve

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

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.