Odyssey
date_fun.i
1 <?php
2 
3 // This function will use php date routines to
4 // allow formatting, it uses the same format strings
5 // as the date function, but it expects an english
6 // textual datetime as the date
7 function dateformat($pFormat, $pDate, $pNull=1) {
8  if (trim($pDate) == "" && $pNull == 1)
9  return $pDate;
10  else
11  return date($pFormat, strtotime($pDate));
12 }
13 
14 
15 // // This will take a date in any format and verify it is a valid date
16 // function isdate($pDate)
17 // {
18 // /*
19 // // This code was replaced -- it was prone to errors in the differences of date values
20 //
21 // $m_val = date("m", strtotime($pDate));
22 // $d_val = date("d", strtotime($pDate));
23 // $y_val = date("Y", strtotime($pDate));
24 // return checkdate($m_val, $d_val, $y_val);
25 // */
26 // // This is now limited to the date format MM/DD/YYYY
27 // if (ereg("^([0-9]{1,2})[/.-]{1}([0-9]{1,2})[/.-]{1}([0-9]{2,4})$", $pDate, $regs)) {
28 // $m_val = $regs[1];
29 // $d_val = $regs[2];
30 // $y_val = $regs[3];
31 // return checkdate($m_val, $d_val, $y_val);
32 // } else {
33 // return false;
34 // }
35 //
36 // }
37 
38 function mdydate ($date) {
39 # $mdays = array(31,28,31,30,31,30,31,31,30,31,30,31);
40  if (strtolower($date) =="now" || strtolower($date) == "today")
41  {
42  $date = date("m/d/Y");
43  }
44  # only allow 0-9 and dash(-)
45  if (preg_match("/[^0-9\-\/ ]/",$date)) { return false;}
46  list ($mm, $dd, $yy) = preg_split ('#[-/]#', $date);
47  $mm = intval($mm);
48  $dd = intval($dd);
49  if( strlen($yy) == 2) {
50  $yy = ($yy < 70 ? "20$yy" : "19$yy");
51  }
52  $yy = intval($yy);
53  if (checkdate($mm,$dd,$yy)) {
54  return "${mm}/${dd}/${yy}";
55  } else {
56  return false;
57  }
58 }
59 ?>