Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Inserting date and time of the user's PC

    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..
    Code:
    <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>
    PHP Code:
    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); 
    Last edited by havish; 10-15-2012 at 06:07 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.

  • #3
    New Coder
    Join Date
    Jul 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    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..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •