Thursday, 28 February 2013

Create Date time combo manually


In a manual page if you want to give a date time combo field, here is the code snippet you'd need on javascript.

var now = new Date();
        if (now.getMonth() == 11) {
            var currentTime = new Date(now.getFullYear() + 1, 0, 1);
        } else {
            var currentTime = new Date(now.getFullYear(), now.getMonth() + 1, 1);
        var month = currentTime.getMonth() + 1;
        var day = currentTime.getDate();
        var year = currentTime.getFullYear();
        day = day.toString();
        month = month.toString();
        if(day.length == '1')
            day = '0' + day;
        if(month.length == '1')
            month = '0' + month;
    var defaultDate  = month + '/' + day +'/' + year;
    var datetimecombo = '<tr valign="middle"><td width="25%" valign="top" scope="row" id="date_start_label">LABEL_OF_YOUR_FIELD<span class="required">*</span></td><td nowrap=""><input type="text"  tabindex="102" title="" maxlength="10" size="11" value="' + defaultDate +'" name="date_start" id="date_start" autocomplete="off"><img border="0" align="absmiddle" id="date_start_trigger" alt="Enter Date" src="index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=jscalendar.gif""index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=jscalendar.gif">&nbsp;</td><td nowrap=""><div id="date_start_time_section"><select tabindex="102" id="date_start_hours" size="1" class="datetimecombo_time"><option></option><option value="00">00</option><option value="01">01</option><option value="02">02</option><option value="03">03</option><option value="04">04</option><option value="05">05</option><option value="06">06</option><option value="07">07</option><option value="08">08</option><option selected="" value="09">09</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option></select>&nbsp;:&nbsp;<select onchange tabindex="102" id="date_start_minutes" size="1" class "datetimecombo_time"><option></option><option value="00">00</option><option selected="" value="15">15</option><option value="30">30</option><option value="45">45</option></select></div></td></tr>';

For now the dropdown is hard coded, but you can get it by > Getting dropdown options in Javascript

Get current date in logged in user's format by

var todayDate = new Date();
var todayDateinUserFormat = todayDate.toLocaleFormat(cal_date_format);


  1. thanks.. but is there a way to get the time format of the current logged in user too?

    var todayDateinUserFormat = todayDate.toLocaleFormat(cal_date_format);

    works fine for the dateformat!

  2. Not that I know of Tom. If I ever come across same, I will definitely update the post. Thank you.


Urdhva Tech Pvt. Ltd. Powered by Blogger.

Urdhva Tech

My photo
SugarCRM Consultants Contact us at Skype : urdhvatech

Search This Blog

Stay connected Socially


Total Pageviews

Popular Posts