Newbie needs to varify a calendar date

Hi,

I have 3 dropdowns. 1 for day, 1 for month and 1 for year.

Does anyone have a script that will varify that the date chosen is a real
calendar date (i.e takes into account different lengths of months and also
leap years)?

Thank you in advance,

Kind regards,

Raj (Newbie)
raj [ Fr, 26 Januar 2007 10:48 ] [ ID #1609374 ]

Re: Newbie needs to varify a calendar date

Message-ID: <0001HW.C1DF7EF5000769C6B01D594F [at] news.zen.co.uk> from raj
contained the following:

>I have 3 dropdowns. 1 for day, 1 for month and 1 for year.
>
>Does anyone have a script that will varify that the date chosen is a real
>calendar date (i.e takes into account different lengths of months and also
>leap years)?


http://uk2.php.net/manual/fi/function.checkdate.php

--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Geoff Berrow [ Fr, 26 Januar 2007 11:08 ] [ ID #1609375 ]

Re: Newbie needs to varify a calendar date

On Fri, 26 Jan 2007 10:08:28 +0000, Geoff Berrow wrote
(in article <kokjr2h1figvs28rhf9hhhcn57ee1v3gmq [at] 4ax.com>):

> http://uk2.php.net/manual/fi/function.checkdate.php

Thanks Geoff
raj [ Fr, 26 Januar 2007 11:28 ] [ ID #1609376 ]

Re: Newbie needs to varify a calendar date

Post removed (X-No-Archive: yes)
Notifier Deamon [ Fr, 26 Januar 2007 19:23 ] [ ID #1609379 ]

Re: Newbie needs to varify a calendar date

Post removed (X-No-Archive: yes)
Notifier Deamon [ Fr, 26 Januar 2007 19:24 ] [ ID #1609380 ]

Re: Newbie needs to varify a calendar date

Tom <tom [at] to.com> wrote:

> On Fri, 26 Jan 2007 09:48:37 +0000, raj wrote...
>>
>> Hi,
>>
>> I have 3 dropdowns. 1 for day, 1 for month and 1 for year.
>>
>> Does anyone have a script that will varify that the date chosen is a
>> real
>> calendar date (i.e takes into account different lengths of months and
>> also
>> leap years)?
>>
>> Thank you in advance,
>>
>> Kind regards,
>>
>> Raj (Newbie)
>>
>
>
> There are a few date settings that are always constant and a couple to
> watch out
> for. There are always 12 months in a year and a month has either 30, 31,
> or 28
> days except leap year where there's 29 in February. You can probably
> define some
> rules, such as which months have how many days. Months might be text
> (Jan.,
> January) or maybe numbers (01, 1, etc) so there's lots of things to
> watch out
> for. : )

Usually I don't bother, just intval() everything and make it a date,
mktime() will swallow faulty dates and change them, i.e. 31-04-2007 will
become 01-05-2007.
--
Rik Wasmus
Rik [ Fr, 26 Januar 2007 19:29 ] [ ID #1609381 ]

Re: Newbie needs to varify a calendar date

Message-ID: <0001HW.C1DF7EF5000769C6B01D594F [at] news.zen.co.uk> from raj
contained the following:

>I have 3 dropdowns. 1 for day, 1 for month and 1 for year.
>
>Does anyone have a script that will varify that the date chosen is a real
>calendar date (i.e takes into account different lengths of months and also
>leap years)?


http://uk2.php.net/manual/fi/function.checkdate.php

--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Geoff Berrow [ Fr, 26 Januar 2007 11:08 ] [ ID #1609390 ]

Re: Newbie needs to varify a calendar date

On 26 Jan, 09:48, raj <r... [at] nospam.com> wrote:
> Hi,
>
> I have 3 dropdowns. 1 for day, 1 for month and 1 for year.
>
> Does anyone have a script that will varify that the date chosen is a real
> calendar date (i.e takes into account different lengths of months and also
> leap years)?
>
> Thank you in advance,
>
> Kind regards,
>
> Raj (Newbie)
This is normally better done in javascript.
Also it does not seem to be at all related to SQL?

There's a new thing out there called Google, you may have heard of it.
If you try using it to search for
javascript date validation
it'll bring up a long list to choose from. I have found
http://www.mattkruse.com/javascript/date/ to be a good one.

Likewise this new fangled Google will allow you to search for
php date validation
and brings up an equally good list for if you really want to do server
side validation. Stuff from phpclasses.org is usually pretty good.

As I say, I can't see the SQL significance in this though.
Captain Paralytic [ Fr, 26 Januar 2007 11:14 ] [ ID #1609391 ]

Re: Newbie needs to varify a calendar date

On Fri, 26 Jan 2007 10:08:28 +0000, Geoff Berrow wrote
(in article <kokjr2h1figvs28rhf9hhhcn57ee1v3gmq [at] 4ax.com>):

> http://uk2.php.net/manual/fi/function.checkdate.php

Thanks Geoff
raj [ Fr, 26 Januar 2007 11:28 ] [ ID #1609392 ]

Re: Newbie needs to varify a calendar date

and stop cross posting!!!!!!!!

"Captain Paralytic" <paul_lautman [at] yahoo.com> wrote in message
news:1169806464.609386.233900 [at] v33g2000cwv.googlegroups.com.. .
> On 26 Jan, 09:48, raj <r... [at] nospam.com> wrote:
>> Hi,
>>
>> I have 3 dropdowns. 1 for day, 1 for month and 1 for year.
>>
>> Does anyone have a script that will varify that the date chosen is a real
>> calendar date (i.e takes into account different lengths of months and
>> also
>> leap years)?
>>
>> Thank you in advance,
>>
>> Kind regards,
>>
>> Raj (Newbie)
> This is normally better done in javascript.
> Also it does not seem to be at all related to SQL?
>
> There's a new thing out there called Google, you may have heard of it.
> If you try using it to search for
> javascript date validation
> it'll bring up a long list to choose from. I have found
> http://www.mattkruse.com/javascript/date/ to be a good one.
>
> Likewise this new fangled Google will allow you to search for
> php date validation
> and brings up an equally good list for if you really want to do server
> side validation. Stuff from phpclasses.org is usually pretty good.
>
> As I say, I can't see the SQL significance in this though.
>
Webwasp [ Fr, 26 Januar 2007 16:24 ] [ ID #1609393 ]

Re: Newbie needs to varify a calendar date

Message-ID: <0001HW.C1DF7EF5000769C6B01D594F [at] news.zen.co.uk> from raj
contained the following:

>I have 3 dropdowns. 1 for day, 1 for month and 1 for year.
>
>Does anyone have a script that will varify that the date chosen is a real
>calendar date (i.e takes into account different lengths of months and also
>leap years)?


http://uk2.php.net/manual/fi/function.checkdate.php

--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Geoff Berrow [ Fr, 26 Januar 2007 11:08 ] [ ID #1609468 ]

Re: Newbie needs to varify a calendar date

On Fri, 26 Jan 2007 10:08:28 +0000, Geoff Berrow wrote
(in article <kokjr2h1figvs28rhf9hhhcn57ee1v3gmq [at] 4ax.com>):

> http://uk2.php.net/manual/fi/function.checkdate.php

Thanks Geoff
raj [ Fr, 26 Januar 2007 11:28 ] [ ID #1609471 ]

Re: Newbie needs to varify a calendar date

I hate having to enter dropdown date entries, why not just a text input
field - it will make your users happier.

I prefer to store dates in the YYYYMMDD format

Here is a a couple functions to validate a text date to a numeric
format but can be easily adapted to whatever output format you prefer.


<?php
/* convert (validate) american date string value to a neumeric date
value
** inputs:
** date string in the format of: "mm/dd/yyyy" or "mm-dd-yyyy" or
"mm.dd.yyyy" (even "1/6/92" is ok)
** with 2 or 4 digit years (2 digit numbers above 20 are assumed in
the 1900s)
** or even YYYYMMDD for us programmer types.
** lowest year acceptable - default 1920
** greatest year accepable - default 2300
** return 0 if empty
** result -1 if date is out of range or input found to be invalid
*/

function datestringtonum($input, $lowyear = 1920, $maxyear = 2300 ) {
$sdate = "";
// convert possible YYYYMMDD entry to MM/DD/YYYY string
if($input > 10000000 and $input < 99999999){
$input = datenumtostring($input);
}
// split date based on different seperators
if ( strpos($input,"/") != 0) { // if seperators are '/'s...
$sdate = explode("/",$input);
} else if ( strpos($input,"-") != 0) { //if seperators are '-'s
$sdate = explode("-",$input);
} else if ( strpos($input,".") != 0) { //if sperators are '.'s
$sdate = explode(".",$input);
}
// if array, so far so good.
$ndate = 0;
if( is_array($sdate)){
// 2 digit years to 4 digit years
if ( $sdate[2] < 99 ) { //check/correct for 2 digit year
$sdate[2] = $sdate[2] + ( $sdate[2] < 20 ? 2000 : 1900 );
}
// check if date is a valid calendar date
if (checkdate($sdate[0],$sdate[1],$sdate[2])) {
//check if date falls within year limits
if ( $sdate[2] < $lowyear or $sdate[2] > $maxyear ) { //
make sure date is within 1920 to next 20 years
$ndate = -1;
} else {
// build a number value YYYYMMDD
$ndate =
$sdate[2].sprintf("%02d",$sdate[0]).sprintf("%02d",$sdate[1] );
}
} else {
$ndate = -1;
}
//if not empty, then it's a bad date string.
} elseif (!empty($input)) {
$ndate = -1;
}
return $ndate;
}

/* convert a readable date number YYYYMMDD to a string date
"MM/DD/YYYY"
** input neumeric: YYYYMMDD
** output string: "mm/dd/yyyy"
*/
function datenumtostring($nval) {
if($nval>0){
$dval =
substr($nval,4,2)."/".substr($nval,6,2)."/".substr($nval,0,4 );
} else {
$dval = "";
}
return $dval;
}
?>
Larry Anderson [ Sa, 27 Januar 2007 05:33 ] [ ID #1610238 ]
PHP » alt.php » Newbie needs to varify a calendar date

Vorheriges Thema: Spell Check, Grammar Check; Output to Word, PowerPoint
Nächstes Thema: Open Source replacement for cpanel's MySQL Databases other than myphpadmin?