Last Updated: May 31, 2021
·
89.67K
· pmaoui

DatePicker with time : TimePicker [jQuery UI]

This article is outdated, thanks to the new component of Mohit Jain that allows to easily create a DatePicker with time (with a beautiful switch between date and time) :
http://tarruda.github.io/bootstrap-datetimepicker/


Timepicker:

Picture

Insert those scripts (you can also host them) before </body> :

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script src="https://rawgithub.com/trentrichardson/jQuery-Timepicker-Addon/master/jquery-ui-timepicker-addon.js"></script>
<script src="https://rawgithub.com/trentrichardson/jQuery-Timepicker-Addon/master/jquery-ui-sliderAccess.js"></script>

 Create an input in your body section :

<input type="text" name="date_begin" id="date_begin" value=""> 

 The magic line :

$('#date_begin,#date_end').datetimepicker(); 

Don't forget the style in <head> :

<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/smoothness/jquery-ui.css" type="text/css" media="all" />
    <style>
    .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }
    .ui-timepicker-div dl { text-align: left; }
    .ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; }
    .ui-timepicker-div dl dd { margin: 0 10px 10px 65px; }
    .ui-timepicker-div td { font-size: 90%; }
    .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }
    .ui-timepicker-rtl{ direction: rtl; }
    .ui-timepicker-rtl dl { text-align: right; }
    .ui-timepicker-rtl dl dd { margin: 0 65px 10px 10px; }
    </style>

Thank you : http://trentrichardson.com/examples/timepicker/

Related protips:

fatal: refusing to merge unrelated histories

2 Responses
Add your response

few js url was not found in git, updATE IT

over 1 year ago ·

Thank you reshmichitra. Actually there is a better way with an other component which is way more beautiful. I've updated this protip.

over 1 year ago ·