Checking Date vaildidation Problem
Posted: Thu Nov 28, 2002 11:32 pm
After sucessfull sorting my previous problem, I must admit I want to improve my code.
At the moment I have 4 if statements checking to see if a date is vaild, I am trying to get it down to one if possible, im sure it is but once again its 05:23am and I have another brain freeze.
This is my previous code:
And im trying to use this code, however I know that its a boolean statement.
But that still gives me script errors, can anyone shed some light on this situation for me please ?
Cheers,
SteJ.
At the moment I have 4 if statements checking to see if a date is vaild, I am trying to get it down to one if possible, im sure it is but once again its 05:23am and I have another brain freeze.
This is my previous code:
Code: Select all
<?php
$string_length = strlen($takings_date);
if($string_length == 10)
{
$format_of_date0 = $takings_date{0};
$format_of_date1 = $takings_date{1};
$format_of_date2 = $takings_date{2};
$format_of_date3 = $takings_date{3};
$format_of_date4 = $takings_date{4};
$format_of_date5 = $takings_date{5};
$format_of_date6 = $takings_date{6};
$format_of_date7 = $takings_date{7};
$format_of_date8 = $takings_date{8};
$format_of_date9 = $takings_date{9};
$takings_date_day_tmp = "$format_of_date0" . "$format_of_date1";
$takings_date_month_tmp = "$format_of_date3" . "$format_of_date4";
if($takings_date_day_tmp > 31)
{
include("error_with_date.php");
}
else if($takings_date_day_tmp < 01)
{
include("error_with_date.php");
}
else if($takings_date_month_tmp < 01)
{
include("error_with_date.php");
}
else if($takings_date_month_tmp > 12)
{
include("error_with_date.php");
}
else
{
$format_of_date_line = "-";
if(strpos($format_of_date2, $format_of_date_line) === 0)
{
if(strpos($format_of_date5, $format_of_date_line) === 0)
{
echo " You have entered the daily takings as the following: - <BR><BR> Amount Taken: <B>£$formatted_amount_taken</B><BR><BR>On the date of : <B>$takings_date</B>";
}
}
}
?>Code: Select all
<?php
if($takings_date_day !> 31 && $takings_date_day !< 01 || $takings_date_month !> 12 && $takings_date_month !< 01 || $takings_date_year !>2037 && $takings_date_year !< 1970)
{
$date_is_correct = checkdate ($takings_date_month, $takings_date_day, $takings_date_year);
if($date_is_correct == true)
{
$takings_date_timestamp = mktime(0,0,0,$takings_date_month,$takings_date_day,$takings_date_year);
}
}
?>Cheers,
SteJ.