You are here: Re: Date/time format for comparison of string to NOW « All PHP « IT news, forums, messages
Re: Date/time format for comparison of string to NOW

Posted by Dano on 10/07/06 12:52

Hey, Pupkin!

I think you'll like PHP so much better than ASP. I, too, made that jump
a number of years ago, and have never looked back. First, you're
jumping to a language that's probably natively installed on a majority
of Web servers (Apache-based) and that's a good thing when you're
working for clients. It's nice to have the ASP experience, too, but I
think you'll find PHP superior.

Dates and times are one reason. PHP, as I understand it, uses a system
of counting the seconds since January 1, 1970 (as I have heard it
described, "The Linux Era," but I may be misinformed!). When you work
with a "raw" PHP time stamp, you'll get a big long number. It's in
actuality the number of seconds since January1, 1970. They won't run
out of numbers of this data type until 2037 or so, as I understand it,
but that'll be a problem for the next generation, not me n' you!

Anyway, the reason I like PHP's date/time system over ASP's is that it
just seems more logical to add and subtract from a number versus a
string to compare dates. Just looking at it, doesn't it seem more
"logical" to subtract 010820051100 from 010820051130, rather than
"October 06 2006 17:45" from "October 16 2006 17:45" (the Microsoft/ASP
format you referenced)?

In PHP, it's often only necessary to compare, add or subtract the two
PHP time stamps, then convert the result to a human-readable output for
use in your page. Or, as in your example, compare the current time to a
set time, and if the current time is greater than the set time, display
the content.

Here's a PHP Manual page reference to get you started, with lots of
good comments and code examples:

http://us2.php.net/date

Hope that helps!

Pupkin wrote:
> Hi,
>
> I need to set some content to only show after a given date and time.
>
> Like:
>
> <?
> $livedate = "October 06 2006 17:45";
> if (date("r") > $livedate) { ?>
> Content here
> <? } ?>
>
>
> I'm used to ASP, where I've gotten into trouble by not forcing my text
> string date/time into the datetime format, so the if-then statement was
> not comparing like-to-like (and several days or hours later, when a
> single digit element changed to two-digits, the code would return
> unintended results).
>
> Is this something I need to worry about with PHP?
>
> I've tried some experiments force-formatting my text string date/time
> with date($livedate), mktime(livedate), etc., but I never end up with
> anything that resembles the date("r").
>
> What do I need to learn to get this to work with reliable results?
>
> Thanks.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация