942,959 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 702
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 29th, 2010
0

getting date value

Expand Post »
I don't know where to start so I just got to ask from the experts . From my MySQL (database) I got a date formatted mm-dd-yyyy (i.e. 01/01/2010), now from my php page there are 3 dropdown/list menus which are for [Month]-[Day]-[Year] and a [TextField] then a [Submit Button]. When I click the [Submit Button] I got to retrieve the date then it will be shown in my texfield. Now the textfield having the value of the date = 01/01/2010 will be the one passing the values on my dropdowns {[Month = January] - [Day = 01] - [Year = 2010]} I just needed the help to how will I start programming as well the design for my database, do I get to have different tables for the parts of the date or what? Thank You for your help.
Last edited by ekseks; Jul 29th, 2010 at 10:58 pm.
Similar Threads
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
ekseks is offline Offline
61 posts
since May 2010
Jul 29th, 2010
0
Re: getting date value
Formatting Dates and Times

DATE_FORMAT(date, format) and TIME_FORMAT assist in the representation of dates and times in formats other than the MySQL default format. Three examples illustrate the syntax:

SELECT DATE_FORMAT('2005-12-31', '%M %d %Y')
December 31 2005

SELECT DATE_FORMAT('2005-12-31', '%D of %M')
31st of December

SELECT TIME_FORMAT('02:17', '%H')
02
Reputation Points: 101
Solved Threads: 134
Practically a Posting Shark
rch1231 is offline Offline
870 posts
since Sep 2009
Jul 30th, 2010
0
Re: getting date value
Thank You Sir rch1231, I'll be posting the code that I'm currently working right now that I also found here in the forums. Thank You again.
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
ekseks is offline Offline
61 posts
since May 2010
Jul 30th, 2010
0
Re: getting date value
I found this here in the forums, so yah it's working but when I changed the format of my date to mm-dd-yyyy, it's entering 00-00-0000, why is that? then as you can see I also have 3 inputfields when I clicked the submit button. I want to get a certain date from my database thus putting [Name of the Month] - [Day] - [Year]. Is that possible? Thanks.

My HTML code:
PHP Syntax (Toggle Plain Text)
  1. <html>
  2. <meta content= "text/html; charset= utf-8" http-equiv="Content-Type"/>
  3. <head>
  4.  
  5. <link type="text/css" href="development-bundle/themes/base/ui.all.css" rel="stylesheet">
  6. <script type="text/javascript" src="development-bundle/jquery-1.3.2.js"></script>
  7. <script type="text/javascript" src="development-bundle/ui/ui.core.js"></script>
  8. <script type="text/javascript" src="development-bundle/ui/ui.datepicker.js"></script>
  9. <script type="text/javascript">
  10. $(function() {
  11. $("#datepick").datepicker({
  12. dateFormat: 'yy-m-d'
  13. });
  14. });
  15. </script>
  16.  
  17. </head>
  18.  
  19. <body>
  20.  
  21. <div>
  22. <form action="insert_db.php" method="post">
  23.  
  24. Date:
  25. <input name="mydate" id="datepick" type="text">
  26.  
  27. <input name="submit" type="submit">
  28. <br>
  29.  
  30. <input name="month" type="text">
  31. <input name="day" type="text">
  32. <input name="year" type="text">
  33.  
  34. <input name="submit" type="submit">
  35.  
  36. </form>
  37. </div>
  38.  
  39. </body>
  40. </html>

PHP Code:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $mydate=$_POST['mydate'];
  3. echo $mydate;
  4. $mydate = date("d/m/Y", strtotime($mydate));
  5.  
  6. $connection = mysql_connect("localhost","root","");
  7. if (!$connection){
  8. die('Could not connect: ' . mysql_error());
  9. }
  10. mysql_select_db("enterdate", $connection);
  11. $sql="INSERT INTO testing (date) VALUES('$mydate')";
  12. echo $sql;
  13. $flag=mysql_query($sql);
  14. if ($flag){
  15. echo "Record Entry successfull. ";
  16. }else{
  17. echo "Record Entry failed. ";
  18. }
  19. mysql_close($connection);
  20. ?>
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
ekseks is offline Offline
61 posts
since May 2010
Jul 30th, 2010
0
Re: getting date value
ok,now while creating database table(testing),what datatype(like integer etc..) you had given.
Reputation Points: 9
Solved Threads: 2
Posting Whiz in Training
niths is offline Offline
299 posts
since Mar 2010
Jul 30th, 2010
0
Re: getting date value
I required an ID which is INT then a date which is a date type
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
ekseks is offline Offline
61 posts
since May 2010
Jul 30th, 2010
0
Re: getting date value
now change that date type to varchar in your database and then check.
Reputation Points: 9
Solved Threads: 2
Posting Whiz in Training
niths is offline Offline
299 posts
since Mar 2010
Jul 30th, 2010
0
Re: getting date value
i thing change date format here. i dont know it works. try once.
PHP Syntax (Toggle Plain Text)
  1.  
  2. $("#datepick").datepicker({
  3.  
  4. dateFormat: 'yy-m-d'
  5.  
  6. });
  7.  
  8. });
Reputation Points: 21
Solved Threads: 35
Posting Pro
muralikalpana is offline Offline
534 posts
since Sep 2009
Jul 30th, 2010
0
Re: getting date value
it's working though i wanted to have my data type as a date, ow well I think this will work for now. so now to my next problem i want to put my selected date (assume that it's only one) in a text box and to different fields [Month] - [Day] - [Year] is it possible?

PHP Syntax (Toggle Plain Text)
  1. <html>
  2. <meta content= "text/html; charset= utf-8" http-equiv="Content-Type"/>
  3. <head>
  4. </head>
  5.  
  6. <body>
  7.  
  8. <div>
  9. <form action="insert_db.php" method="post">
  10.  
  11.  
  12. <input name="month" type="text">
  13. <input name="day" type="text">
  14. <input name="year" type="text">
  15.  
  16. <input name="wholedate" type="text">
  17.  
  18. <input name="submit" type="submit">
  19. </form>
  20. </div>
  21.  
  22. </body>
  23. </html>
Last edited by ekseks; Jul 30th, 2010 at 2:38 am.
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
ekseks is offline Offline
61 posts
since May 2010
Jul 30th, 2010
0
Re: getting date value
yes, use explode fuction , slipt the date and display the fields . see this link
Reputation Points: 10
Solved Threads: 7
Junior Poster in Training
raju_boini525 is offline Offline
53 posts
since Aug 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP Vending Machine
Next Thread in PHP Forum Timeline: mail() function: how to add <br /> in the $message received





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC