Web Analytics Made Easy -
StatCounter date format problem - CodingForum

Announcement

Collapse
No announcement yet.

date format problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • date format problem

    hi,

    I want to use a date that is selected in a drop down by the user from
    a previous page in a sql query.
    The date is $thedate and in the format eg 12/04/2004 when i post the
    value.

    PHP Code:

    $thedate 
    $_POST[sel_date]; 
    but because the format is in a string i cannot compare it to a value in my
    table in the database because the value in the databse is in the format 2004-04-12.


    I have tried to use this ....

    PHP Code:


    $datearray 
    getdate($thedate);

    foreach (
    $datearray as $key => $val)
    {
    print 
    "$key$val<br>";

    But i just get the unix epoch value. I guess this is because the arguement
    for getdate() is not a not a timestamp but a string.


    Can anyone help me figure what i can do to solve this problem.


    Thanks

  • #2
    Check out the mktime() function on the php.net site. It may help.
    Create accessible online surveys -::- Koobten.com - compare netbook prices and reviews -::- Affordable, reliable hosting for less than $20 per year
    Zend Certified Engineer

    Comment


    • #3
      Re: date format problem

      I want to use a date that is selected in a drop down by the user from
      a previous page in a sql query.
      The date is $thedate and in the format eg 12/04/2004 when i post the
      value.
      I wouldn't do that...
      Have a look at the W3C guidelines.
      --> http://www.w3.org/QA/Tips/iso-date
      PHP Code:
      $thedate $_POST[sel_date]; 
      This is bad php syntax, use quotes for array keys.
      $_POST["sel_date"]; or $_POST['sel_date'];
      but because the format is in a string i cannot compare it to a value in my
      table in the database because the value in the databse is in the format 2004-04-12.
      --> http://php.net/strtotime
      --> http://www.gnu.org/software/tar/manu...ter/tar_7.html (for the input formats of strtotime)
      PHP Code:
      $datearray getdate($thedate);
      foreach (
      $datearray as $key => $val)
      {
      print 
      "$key$val<br>";

      The function getdate requires a timestamp as argument.
      --> http://php.net/getdate
      But i just get the unix epoch value. I guess this is because the arguement
      for getdate() is not a not a timestamp but a string.
      Exactly.
      Can anyone help me figure what i can do to solve this problem.
      hope I helped.

      saludo
      piz
      www.united-scripts.com
      www.codebattles.org

      Comment

      Working...
      X