Date Question – PHP

  php

Q(Question):

Hi,

We have a form where the user selects a date from a calendar, the date
is in the format May 23, 2008.

The date in the datebase is in the format 05212008.

What we need to do is get the starting and ending date of the week for
the date selected in the form: May 23, 2008, and then get the records
from the database where the dates fall within that range.

So, from that date / format: May 23, 2008, how can I find the
starting and ending dates for the week the date falls in???

I’m still searching…….

Thanks!

John

A(Answer):

On Wed, 28 May 2008 01:11:57 +0200, Mtek <mt**@mtekusa.comwrote:

We have a form where the user selects a date from a calendar, the date
is in the format May 23, 2008.

The date in the datebase is in the format 05212008.

What we need to do is get the starting and ending date of the week for
the date selected in the form: May 23, 2008, and then get the records
from the database where the dates fall within that range.

So, from that date / format: May 23, 2008, how can I find the
starting and ending dates for the week the date falls in???

Use the date/time funcions available to you in your database (assuming you
had the common sense to store that value as a date, which all major
databases understand nowadays….). Ask in a group dedicated to your
choice of database how they’d solve it. Most likely a simple ‘WHERE
WEEK(date) = WEEK(your data)’ will get you all you want.

Failing that, your options are either using strtotime() to get relative
dates, or basic unix timestamps (worst case scenario: created with sub
strings) and some easy math. I strongly suggest to let a database
(probably highly optimised for this kind of thing) handle it.

Rik Wasmus
….spamrun finished

LEAVE A COMMENT