...

View Full Version : Inserting date and time of the user's PC



havish
10-15-2012, 06:05 PM
I need to insert into my database, the date and time of the user's pc and not the server. For this I am giving a textbox to the user to select date. But I do not know how to select the time at the time of hitting the submit button. The date field in my table is of datetime type. So the date is getting inserted through post method which is shown below. I need to know how can I insert time also..

<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#datepicker').datepicker({
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true});
});

</script>


echo '<form action="" method="post">
Please select date :<input name="date" id="datepicker" type="text" />
<input type="submit" name ="submit2" id="submit2" value ="submit"/></form>';
$date = $_POST['date'];
$query = "INSERT INTO `samp`(`date`) VALUES ('".$date."')";
mysql_query($query);

Fou-Lu
10-15-2012, 06:54 PM
This is purely a JS issue. All that you have to do is modify whatever you have to do in your js to pass it to the PHP code. Insert it as a datetime datatype. PHP is incapable of reading date or time from the client.

Which leads to the question though: why? You cannot properly run any statistical analysis involving time if you let the client provide their own date and time.

havish
10-15-2012, 07:46 PM
This is purely a JS issue. All that you have to do is modify whatever you have to do in your js to pass it to the PHP code. Insert it as a datetime datatype. PHP is incapable of reading date or time from the client.

Which leads to the question though: why? You cannot properly run any statistical analysis involving time if you let the client provide their own date and time.

This date which I am getting from the client is for marking attendance for the particular day. ie the client selects the date of the attendance to be taken..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum