Reputation: 207
I have already been able to get the variable gamedate into my database but would also like to put the day of the week into the database or var dayOfWeek (a number for the day of the week- 0 for sunday, 1 for monday).
I don't really know if I am putting together the script correctly so I thought I would post that as well.
<script>
$(function() {
$( "#datepicker" ).datepicker({
minDate: -20,
maxDate: "+1M +10D",
constrainInput: true, // prevent letters in the input field
minDate: new Date(), // prevent selection of date older than today
autoSize: true, // automatically resize the input field
currentText: 'Now',
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
});
});
function(event, ui) {
var date = $(this).datepicker('getDate');
var dayOfWeek = date.getUTCDay();
};
</script>
<p>Date: <input name="gamedate" type="text" id="datepicker" ></p></div><!-- End demo -->
Just for additional information... I insert the data into the database using the post method
$gamedate = mysql_real_escape_string($_POST['gamedate']);
$mysql_query = "INSERT INTO soccer_games (gamedate) VALUES ('$gamedate')";
Upvotes: 0
Views: 1179
Reputation: 7388
I suggest not storing the name of the day in the database (Monday, Tuesday, Wed...etc) Instead, perform getUTCDay(), or a server-side equivalent when you perform your database READ in the future...
Storing the name of the day is redundant data, as it can be deduced directly from the more specific date that you're storing.
Upvotes: 1
Reputation: 6136
I guess, you want to write a function that converts the date string to timestamp. And I also believe that your string is in the form of 06/03/2011
So, for this scenario, you would want to do...
(php code)
public function dateToStamp($str) {
if( is_numeric($str) || $str==0 ) return $str;
if( (int)strstr($str, "/")>=0 )
$date = explode("/",$str);
else
$date = explode("-",$str);
return mktime(0,0,0,$date[0],$date[1],$date[2]);
}
The above code handles, a) timestamp input b) 12/24/2011 c) 12-24-2011
Upvotes: 0