Jump to content

Date


user4fun

Recommended Posts

I have a form that allows the user to enter a date. This date is saved in an Mysql Table with the field type set to "date".It keeps saving the information in YYYY-MM-DD. Format.I need the user to enter the information in a simple format (ie MM-DD-YY. example 11-06-11)and when submitted, I need it to be stored as Tue Nov 6Please help.Starting point. Should I have dorp down boxes with all the weeks days, then another for the months, and another for the day? If so, will the information be stored in a manner that the php script can later compare dates?? and what if the user enters Tuesday Nov 6th, but november 6th is actually a wednesday?? I need it to be right.Thank you in advance.

Link to comment
Share on other sites

You don't change the way the date is stored. If you want to change the format of the date when you select it, you can, but if you're telling MySQL to store a date it's going to store it in its own format. Don't have your users pick the day, just the month, date, and year. You can also show a calendar where they can click on a date and see what day it is.http://dev.mysql.com/doc/refman/5.5/en/dat...ion_date-format

Link to comment
Share on other sites

OK, that is giving me some more ideas. Just so I understand how can I convert the YYYY-MM-DD format that is pulled from the table to the Wed Aug 10,2011 format that the webpage will display?, and when the user entered 08-11-2011 it will be converted to 2011-08-11 format before it is stored?Thank you for all your help

Link to comment
Share on other sites

you can use the date object and pass it a timestamp and then have it format the date you want. so if you get 08-11-2011

$userDate = '08-11-2011';$sqlDate = date('Y-m-d', strtotime($userDate));

you might just want to spend some time reading the date page in the PHP manual.http://php.net/manual/en/function.date.php

Link to comment
Share on other sites

date expects a timestamp in the second parameter, not a formatted date string. You'll need to convert the string to a timestamp. strtotime will create a timestamp from a string. Note that this function has already been pointed out to you. When you visit the link, take the time to look at the left of your screen to review all the time functions available to you.FWIW, you'll save some trouble if you save your date as a timestamp in the database.
Link to comment
Share on other sites

$x= $row['Ad_Start']; $y = date('Y', $x); echo $y;echo "<br>";echo $row['Ad_Start'];

gives me19702012-08-29 // this is the orignal value.

you should re-read my first post. (post #4 in thread)I seconds DD's recommendation to use timestamps. I always prefer to have my times in that format in a database. Easier and more consistent for performing calculations and formatting.
Link to comment
Share on other sites

I forgot to thakn you for that earlier, I did use itand ti works great. I was trying to learn more things including the EXTRACT() and play arround with it to only pull out the year, then month, then day values independently to do more things with them.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...