javascript - i am inserting date to database in the format yyyy/mm.dd -


i had problem inserting date database.my database mysql generated date automatically input field.but mysql date format yyyy/mm/dd.so want in format. plz any1 me .

<tr>                    <td class="label">                     <label for="bill-date">bill date                     </label>                  </td>                   <td>                     <input id="bill_date" class="datepicker" type="date" name="bill_date" required>                  </td>                  <script type="text/javascript">                             document.getelementbyid("bill_date").value = date();                 </script>               </tr> 

check jsfiddle

use format prototype below.

today = new date(); var datestring = today.format("yy/mm.dd"); alert(datestring); 

the prototype library

/*  * date format 1.2.3  * (c) 2007-2009 steven levithan <stevenlevithan.com>  * mit license  *  * includes enhancements scott trenda <scott.trenda.net>  * , kris kowal <cixar.com/~kris.kowal/>  *  * accepts date, mask, or date , mask.  * returns formatted version of given date.  * date defaults current date/time.  * mask defaults dateformat.masks.default.  */  var dateformat = function () {     var token = /d{1,4}|m{1,4}|yy(?:yy)?|([hhmstt])\1?|[llosz]|"[^"]*"|'[^']*'/g,         timezone = /\b(?:[pmcea][sdp]t|(?:pacific|mountain|central|eastern|atlantic) (?:standard|daylight|prevailing) time|(?:gmt|utc)(?:[-+]\d{4})?)\b/g,         timezoneclip = /[^-+\da-z]/g,         pad = function (val, len) {             val = string(val);             len = len || 2;             while (val.length < len) val = "0" + val;             return val;         };      // regexes , supporting functions cached through closure     return function (date, mask, utc) {         var df = dateformat;          // can't provide utc if skip other args (use "utc:" mask prefix)         if (arguments.length == 1 && object.prototype.tostring.call(date) == "[object string]" && !/\d/.test(date)) {             mask = date;             date = undefined;         }          // passing date through date applies date.parse, if necessary         date = date ? new date(date) : new date;         if (isnan(date)) throw syntaxerror("invalid date");          mask = string(df.masks[mask] || mask || df.masks["default"]);          // allow setting utc argument via mask         if (mask.slice(0, 4) == "utc:") {             mask = mask.slice(4);             utc = true;         }          var _ = utc ? "getutc" : "get",             d = date[_ + "date"](),             d = date[_ + "day"](),             m = date[_ + "month"](),             y = date[_ + "fullyear"](),             h = date[_ + "hours"](),             m = date[_ + "minutes"](),             s = date[_ + "seconds"](),             l = date[_ + "milliseconds"](),             o = utc ? 0 : date.gettimezoneoffset(),             flags = {                 d:    d,                 dd:   pad(d),                 ddd:  df.i18n.daynames[d],                 dddd: df.i18n.daynames[d + 7],                 m:    m + 1,                 mm:   pad(m + 1),                 mmm:  df.i18n.monthnames[m],                 mmmm: df.i18n.monthnames[m + 12],                 yy:   string(y).slice(2),                 yyyy: y,                 h:    h % 12 || 12,                 hh:   pad(h % 12 || 12),                 h:    h,                 hh:   pad(h),                 m:    m,                 mm:   pad(m),                 s:    s,                 ss:   pad(s),                 l:    pad(l, 3),                 l:    pad(l > 99 ? math.round(l / 10) : l),                 t:    h < 12 ? "a"  : "p",                 tt:   h < 12 ? "am" : "pm",                 t:    h < 12 ? "a"  : "p",                 tt:   h < 12 ? "am" : "pm",                 z:    utc ? "utc" : (string(date).match(timezone) || [""]).pop().replace(timezoneclip, ""),                 o:    (o > 0 ? "-" : "+") + pad(math.floor(math.abs(o) / 60) * 100 + math.abs(o) % 60, 4),                 s:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]             };          return mask.replace(token, function ($0) {             return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);         });     }; }();  // common format strings dateformat.masks = {     "default":      "ddd mmm dd yyyy hh:mm:ss",     shortdate:      "m/d/yy",     mediumdate:     "mmm d, yyyy",     longdate:       "mmmm d, yyyy",     fulldate:       "dddd, mmmm d, yyyy",     shorttime:      "h:mm tt",     mediumtime:     "h:mm:ss tt",     longtime:       "h:mm:ss tt z",     isodate:        "yyyy-mm-dd",     isotime:        "hh:mm:ss",     isodatetime:    "yyyy-mm-dd't'hh:mm:ss",     isoutcdatetime: "utc:yyyy-mm-dd't'hh:mm:ss'z'" };  // internationalization strings dateformat.i18n = {     daynames: [         "sun", "mon", "tue", "wed", "thu", "fri", "sat",         "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"     ],     monthnames: [         "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec",         "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"     ] };  // convenience... date.prototype.format = function (mask, utc) {     return dateformat(this, mask, utc); }; 

source: http://blog.stevenlevithan.com/archives/date-time-format

your example code

<tr>       <td class="label">         <label for="bill-date">bill date</label>     </td>      <td>         <input id="bill_date" class="datepicker" type="date" name="bill_date" required>     </td>     <script type="text/javascript">         today = new date();         var datestring = today.format("yy/mm.dd");         document.getelementbyid("bill_date").value = datestring;         </script> </tr> 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -