text to date and insert to mysql...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PhilM

    text to date and insert to mysql...

    Kindly break out the 4x2 and bring me to my senses.
    I seem to have gotten myself totally confused with php.net, mysql.org pages
    on dates etc, as well as groups.google.

    Could someone explain, even using pseudo code, how to take a text input I
    have set up as YYYY-MM-DD using php, and convert to a value mysql will
    insert into a Date (not timestamp, not datetime) field.

    Kind regards,
    and thanks in advance,
    PhilM


  • PhilM

    #2
    Re: text to date and insert to mysql...


    "Roger Smith" <roger@ns_jadeb ox.com> wrote in message
    news:9iBPa.6282 $k85.422692@twi ster.tampabay.r r.com...[color=blue][color=green]
    > > Could someone explain, even using pseudo code, how to take a text input[/color][/color]
    I[color=blue][color=green]
    > > have set up as YYYY-MM-DD using php, and convert to a value mysql will
    > > insert into a Date (not timestamp, not datetime) field.[/color]
    >
    > MySQL has no problem with dates in "YYYY-MM-DD" format.
    >
    > For example,
    >
    > $result = mysql_query("in sert into test (created) values[/color]
    ('2003-07-11')");[color=blue]
    >
    > -- Roger
    > http://www.harrynilsson.com/
    >
    >[/color]
    Yes, I know. I did mention a lump of 4x2...

    My prblem was not the format after all(obiously), but the way I was trying
    to check if the date had already been entered.
    What I tried to do, was use in_array, to compare my date with those already
    in the table.
    (I didn't realize that it wouldn't work unless using strict, which I have
    not yet understood in full)
    This then had me Assuming I had the format wrong ;)
    Ended up using:

    $queryNewTest = "select compDate from tbl_competition where compDate =
    '$concatDate'";
    $resultNewTest = mysql_query($qu eryNewTest) or die("Query failed
    :-".MYSQL_ERROR() );
    $numNewRows = mysql_num_rows( $resultNewTest) ;
    $textNewDate = formatdate($con catDate);
    if ($numNewRows){
    $newTextAlert = " <b class=\"alert\" >$textNewDate </b> already exists";
    echo $newTextAlert;
    }
    else {
    $newOkDate = "Will enter $textNewDate into system.";
    echo $newOkDate;
    }

    $concatDate is my string taken from 3 text boxes, checked, and joined.
    formatdate() is a function found on php.net user comments, and turns date
    into format
    Tuesday, 22 Apr 2003

    else section will ultimately contain insert statement... but not this
    morning, 2:15am... I'm going to bed.

    Thanks for replying.
    Regards
    PhilM


    Comment

    Working...