Add today's date and time to filename

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Add today's date and time to filename

Postby pstrg » Fri Jan 17, 2020 11:28 pm

Would like to add to filename today'sdate (as yyyy-mm-dd) followed by time (as hh.mm).
however, being entirely new to javascript, I'm a bit unsecure.
Could someone shed some light on how to?
pstrg
 
Posts: 6
Joined: Sun Dec 07, 2008 3:41 pm

Re: Add today's date and time to filename

Postby Admin » Sat Jan 18, 2020 2:59 am

Code: Select all
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date +' '+time;

newName = name + '-' + dateTime;
Admin
Site Admin
 
Posts: 1895
Joined: Tue Mar 08, 2005 8:39 pm

Re: Add today's date and time to filename

Postby pstrg » Sun Jan 19, 2020 2:49 am

Thanks!
pstrg
 
Posts: 6
Joined: Sun Dec 07, 2008 3:41 pm


Return to Javascript Renaming