Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Date validation

Links for php scripts

Moderators: macek, egami, gesf

Date validation

Postby sansoft » Sat May 15, 2004 8:26 pm

Hi all,

i have got two DROPDOWN boxes one for Startdate and other for EndDate.
i have prepared a file datefunct.php which contains three functions getmonth,getyear,getday....i am calling these functions at an appropriate place.

Now i want to validate the dates ie startdate< enddate.upto this time the code does not validate anything..u can fill up anything u wish.

the select names(for the dropdowns ) for the three functions are "month","year","day".

How should i accomplish it?
plz help

Sansoft
sansoft
New php-forum User
New php-forum User
 
Posts: 44
Joined: Fri May 07, 2004 2:16 am
Location: India

Postby gesf » Sun May 16, 2004 11:52 am

Please see this!
I´m almost sure if your dates are in the same format, you can make a normal comparison, i mean like you said: startdate < enddate.

Example (This works):
Code: Select all
<?php
$today = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d"), date("Y")));

// The same format we´ve made above!
$date_to_compar = '2004-05-13';

if($today > $date_to_compar){

echo $today . ' is greater than ' . $date_to_compar;

}else{

echo $today . ' is less than ' . $date_to_compar;

}
?>
User avatar
gesf
Moderator
Moderator
 
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

javascript code please

Postby sansoft » Mon May 17, 2004 8:23 am

Hi all,

Can anyone suggest a javascript code for my problem please.......

Sansoft
sansoft
New php-forum User
New php-forum User
 
Posts: 44
Joined: Fri May 07, 2004 2:16 am
Location: India

Postby gesf » Mon May 17, 2004 11:32 am

Well you better stop by google. You´ll find some great examples!

Here is a lil´example.
I´m not a pro in javascript, so this isn´t the right way to do this.
It works anyway:
Code: Select all
<html>
<head>
<script>
function compar(){
date1 = new Date(2004, 11, 15);
date2 = new Date(2004, 11, 11);
with(document){
  write('<pre>');
    if(date1 > date2){
      writeln(date1 + ' (is greater than) ' + date2);
    }else{
      writeln(date1 + ' (is less than) ' + date2);
    }
  write('<pre>');
}
}
</script>
</head>
<body>
<table>
  <tr>
    <a href="javascript:compar()">compar it!</a></td>
  </tr>
</table>
</body>
</html>
User avatar
gesf
Moderator
Moderator
 
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby crazyfox » Sun Jun 13, 2004 12:32 am

I have a solution for date validation, but before I make an assumption of what it is u really trying to achieve I must ask two questions.

1. Will the start and end dates be inserted into a database?
2. What format are you using in your drop down boxes....
i.e 14/06/2004
14-06-2004
14-Jun-2004


If on the other hand you just want to compare start and end date boxes against each other or the system time then the snippet code that [/b]gesf supplied seem OK.

Let us know.....
User avatar
crazyfox
New php-forum User
New php-forum User
 
Posts: 19
Joined: Wed Jun 02, 2004 7:59 am


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron