I'm using Node (Express.js) to update a MySQL database with the date now and it works fine but my code is a little repetitious.
var newYears = new Date();
var newMonths = new Date();
var newDays = new Date();
var newHours = new Date();
var newMinutes = new Date();
var newSeconds = new Date();
var yearNow = newYears.getFullYear();
var monthNow = newMonths.getMonth();
var dayNow = newDays.getDate();
var hourNow = newHours.getHours();
var minuteNow = newMinutes.getMinutes();
var secondNow = newSeconds.getSeconds();
var timeNow = yearNow + '-' + ( monthNow + 1 ) + '-' + dayNow + ' ' + hourNow + ':' + minuteNow + ':' + secondNow;
How few characters can the same result be achieved with?
You could cut out some overhead like this:
var basedate = new Date();
var yearNow = basedate.getFullYear()
var monthNow = basedate.getMonth();
var dayNow = basedate.getDate();
var hourNow = basedate.getHours();
var minuteNow = basedate.getMinutes();
var secondNow = basedate.getSeconds();
var timeNow = yearNow + '-' + ( monthNow + 1 ) + '-' + dayNow + ' ' + hourNow + ':' + minuteNow + ':' + secondNow;
Alteratively someone else might set up an array splitting the component parts of the Dateobject to save a few processor cycles, but unless you find yourself desperately needing to cut down the execution time of your script, don't worry.
A good rule of thumb is if you can't quantify the speed-up, you shouldn't try to optimize for it. If it ain't broke...
On the other hand, you might like http://perlgolf.sourceforge.net/