Date with 'Zeros' Output
I have a date picker that give me this result: e.g. 2011-29-08
When it is inserted in mysql, it outputs '0000-00000'.
What can I do?
I know "strftime("%Y-%m-%d %H:%M:%S", time());"
But I have no timestamp to put as an argument.
The only data I can use is the data that the date picker produces (yyyy-dd-mm)
Whats the proper thing to do?
I'll wait for your replies. Thanks!
rakwel10
Junior Poster in Training
68 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
actually your format is yyyy-dd-mm
so change your strftime like
strftime("%Y-%d-%m", $datevariable);"
or change your date picker setting to yyyy-mm-dd, then you can directly insert date variable without strftime.
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
Thanks for you reply...
I still get zeros...
this is my code
$initial_date = mysql_prep($_POST['date']);
$date = strftime("%Y-%d-%m", $initial_date);
"$_POST['date']" has data = yyyy-dd-mm
Pls help. tnx
rakwel10
Junior Poster in Training
68 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
it does displays yyyy-dd-mm.
but when i insert it in mysql (the data type of the column is 'Date'),
it still returns zeros :(
rakwel10
Junior Poster in Training
68 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
I think you do not need mysql_prep
try following code without mysql_prep
$initial_date = $_POST['date'];
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
I did all what you've suggested...
I remove the mysql_prep, rearrange the month and day and others...
Still it didnt work...
I tested the value of "$_POST['date'];" before inserting in mysql.
The date alerted right (2011-08-29). Sadly, when inserted to mysql, zeros are still there...
Any other options? what do you think?
thanks for your help by the way..
rakwel10
Junior Poster in Training
68 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
echo $query before execution and copy it and run in phpmyadmin.
also post that output query here.
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
Here is the query..
INSERT INTO tbl_tour_profile ( `tour_code`, `tour_name`, `subj_code`, `subj_name`, `section`, `subj_teacher`, `destination`, `date`, `path`, `tour_amount`, `expected_num_participants`, `estimated_tour_budget`)
VALUES ('10006', 'Tour MIS', 2122, '6MIS', 'N-201', ' Maria Allen J. Quiambao', 'HAU', 2011-08-31, 'tourdocs/10006_Doc1.doc','234','234','54756')
as you can see, the date format is right (yyy-mm-dd).
Is the problem in mysql?
rakwel10
Junior Poster in Training
68 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
you must wrap around single quotes
....,'$initial_date',.....
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
initial_date is not part of the query coz its not in the field. Do you mean date?
...`subj_teacher`, `destination`, `date`,...
It does have quotes. Actually, I copied sql query in phpmyadmin.
rakwel10
Junior Poster in Training
68 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
in my desperate situation,
I tried changing the "date" datatype into a varchar or text.
The result is surprising and WEIRD...
It gave me a year - "1972".
Weird isnt it? Do you think mysql is the problem?
rakwel10
Junior Poster in Training
68 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
@KP - 1 for your patience!
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
KP,
the one with the red mark, thats the value of date field and it has quotes on it. what do you think?
INSERT INTO tbl_tour_profile ( `tour_code`, `tour_name`, `subj_code`, `subj_name`, `section`, `subj_teacher`, `destination`, `date`, `path`, `tour_amount`, `expected_num_participants`, `estimated_tour_budget`)
VALUES ('10006', 'Tour MIS', 2122, '6MIS', 'N-201', ' Maria Allen J. Quiambao', 'HAU', '2011-08-31', 'tourdocs/10006_Doc1.doc','234','234','54756')
rakwel10
Junior Poster in Training
68 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
you need to quote around date and text, only numbers are allowed to write without qoutes
so
1) do not change your datatype
2) post your query (not output) only php mysql query with variables names, i will prepare query for you.
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
Here it is...
" INSERT INTO tbl_tour_profile ( `tour_code`, `tour_name`, `subj_code`, `subj_name`,
`section`, `subj_teacher`, `destination`, `date`, `path`, `tour_amount`, `expected_num_participants`, `estimated_tour_budget`)
VALUES ('$tourId', '{$tourName}', {$classCode}, '{$subject}', '{$section}', '{$teacher}', '{$destination}', {$date}, '{$path}','{$amount}','{$expected_num_participants}','{$estimated_tour_budget}')";
rakwel10
Junior Poster in Training
68 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0