Re: date comparison
| From: | Joe Stump | Date: | Mon, 15 Jan 2001 14:53:04 +0000 |
| Subject: | Re: date comparison | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-34628@lists.php.net to get a copy of this message | ||
Yes - it may work like you are saying, but I would use a timestamp to be sure.
You can make comparisons on regular date formats from within MySQL with the
date or datetime fields.
--Joe
On Mon, Jan 15, 2001 at 12:39:13PM -0600, Jacky@lilst wrote:
> all right, now I have both date values in the same format (yyyy/mm/dd), say
> $Date1 = 20010115 and $Date2 =20010120. If what I want is to find out if
> $Date1 come before $Date2, can I just use this sniplet below?
>
> if ($Date1 < $Date2) {
> ...........
> } else {
> .......
> }
>
> Do I still need to use mktime() for this purpose?
> cheers
> Jack
> jacky@activelifestyle.com
> "There is nothing more rewarding than reaching the goal you set for
> yourself"
> ----- Original Message -----
> From: Jason Murray <Jason.Murray@melbourneit.com.au>
> To: 'Jacky@lilst' <jacky@activelifestyle.com>;
> <php-general@lists.php.net>
> Sent: Sunday, January 14, 2001 11:37 PM
> Subject: RE: [PHP] date comparison
>
>
> > > can I used the value from that variables to compare with another
> > > date value? Say another date value I will use is also retrieved
> > > from a field in table which is in Date data type as well.
> >
> > When you get into this stuff, it all starts getting a lot more
> complicated.
> >
> > If you want to compare two fields, make sure they're in the same format.
> >
> > Basically, make sure you use four digit years and two digit months and
> > days to create your birthday fields, so they look like (for example, with
> > today's date, 20010115 instead of 2001115 - that second one could really
> > be anything).
> >
> > If you're sure you're storing the birthdays properly, you can then cut
> > the strings up when you pull them out of the database, the first 4 chars
> > are the year, the next two make the month (regardless of the actual month,
> > this way it'll be "01" not "1"), then the day.
> >
> > Do that for both of the dates.
> >
> > Now, you can use the mktime() command to turn them into unix tiumestamps.
> >
> > $unixtimeme = mktime(myhour, myminute, mysecond, mymonth, myday,
> myyear);
> > $unixtimethem = mktime(theirhour, theirminute, theirsecond, theirmonth,
> > theirday, theiryear);
> >
> > Now, a unix timestamp is the number of seconds from 00:00:01, Jan 1, 1970.
> >
> > You can figure out the difference in seconds between the two timestamps.
> >
> > Divide it by (24*3600), which is the number of seconds in a day, and there
> > you have the number of days between the dates.
> >
> > Incidentally, if you want to find the number of days between your
> birthDAYS,
> > then you'll want to substitute in a specific year in the mktime()
> statements
> > above, as you'll otherwise end up with the number of days between your
> exact
> > DATES of birth.
> >
> > Jason
> >
> > --
> > Jason Murray
> > jasonm@melbourneit.com.au
> > Web Design Team, Melbourne IT
> > Fetch the comfy chair!
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
Joe Stump, PHP Hacker
joestump98@yahoo.com
http://www.miester.org/