By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,818 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,818 IT Pros & Developers. It's quick & easy.

text to date and insert to mysql...

P: n/a
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
Jul 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Roger Smith" <roger@ns_jadebox.com> wrote in message
news:9i*******************@twister.tampabay.rr.com ...
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.
MySQL has no problem with dates in "YYYY-MM-DD" format.

For example,

$result = mysql_query("insert into test (created) values

('2003-07-11')");
-- Roger
http://www.harrynilsson.com/

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($queryNewTest) or die("Query failed
:-".MYSQL_ERROR());
$numNewRows = mysql_num_rows($resultNewTest);
$textNewDate = formatdate($concatDate);
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
Jul 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.