calin-beard
11/13/2017 - 5:19 PM

Push date and time to hidden field

<!--START code current date and time to 2 hidden fields-->
<script>
  $(document).ready(function() {
      var date = function() {
          var dateObject = new Date();
          var disp = [];
          var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

          disp.push(monthNames[dateObject.getMonth()]);
          disp.push(dateObject.getDate());
          disp.push(dateObject.getFullYear());

          return disp.join(' ');
      }; //function

      var time = function() {
          var dateObject = new Date();
          var disp = [];
          disp.push(dateObject.getHours());
          disp.push(dateObject.getMinutes());
          disp.push(dateObject.getSeconds());
          
          return disp.join(':');
      }; //function

      $('input[name="' + base64_encode('date') + '"]').attr("value", date()); //append the date to the field
      $('input[name="' + base64_encode('time') + '"]').attr("value", time()); //append the time to the field

  }); // ready
</script>
<!--END code current date and time to 2 hidden fields-->
<!--START code current date and time to hidden field-->
<!--Zoho requires the format yyyy-mm-dd hh:mm:ss-->
<script>
    $(document).ready(function() {
        var gDate = function() {
            var dateObject = new Date();
            var disp = [];

            disp.push(dateObject.getFullYear());
            disp.push(dateObject.getMonth() + 1);
            disp.push(dateObject.getDate());

            return disp.join('-');
        }; //function

        var gTime = function() {
            var dateObject = new Date();
            var disp = [];
            disp.push(dateObject.getHours());
            disp.push(dateObject.getMinutes());
            disp.push(dateObject.getSeconds());
            
            return disp.join(':');
        }; //function
        
        var datetime = gDate() + ' ' + gTime();
        $( 'input[name="'+ base64_encode( 'datetime' ) +'"]').attr("value", datetime );

    }); // ready

</script>
<!--END code current date and time to hidden field-->
<!--START code current date and time to hidden field-->
<!--Format dd/mm/yyyy dd:mm AM-->
<script>
    $(document).ready(function() {
        var gDate = function() {
            var dateObject = new Date();
            var disp = [];

            disp.push(dateObject.getDate());
            disp.push(dateObject.getMonth() + 1);
            disp.push(dateObject.getFullYear());

            return disp.join('/');
        }; //function

        var gTime = function() {
            var dateObject = new Date();
            var disp = [];
            var hours = dateObject.getHours();
            if (hours != 12) {
                disp.push(hours % 12);
            } else {
                disp.push(12);
            }
            disp.push(dateObject.getMinutes());
            if (hours < 12) {
                return disp.join(':') + ' AM';
            } else {
                return disp.join(':') + ' PM';
            }
        }; //function
        
        var datetime = gDate() + ' ' + gTime();
        $( 'input[name="'+ base64_encode( 'datetime' ) +'"]').attr("value", datetime );

    }); // ready

</script>
<!--END code current date and time to hidden field-->