Convert long date to YYYYMMDD

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

Convert long date to YYYYMMDD

Postby Vn5eOJK » Thu Oct 06, 2022 1:20 am

I am trying to convert files that have a date in long format (such as "10 September 1966") as part of their name into YYYYMMDD format.

In BRU 3.4.4 JS I seem to be able to successfully do;
Date.parse(longDateString)
and get the correct epoch offset.

But, I get errors trying to use any of the functions that would return this date as a string or as numeric parts for each component.

See, for example;
https://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object

Ideally, I'd like to use what seems to be the simplest solution;
dateObject.toISOString().slice(0,10).replace(/-/g,"");

But, I get an error trying to use that toISOString() function, although it does seem to be part of the ECMA-262 5th Ed spec.

I know I can brute force this and code my own long date parser, but is there some way I can use the built-in Date object or other datetime functions to do this in a line or two of code? None of the examples on the URL above seem to work in BRU.
Vn5eOJK
 
Posts: 11
Joined: Sat Jan 19, 2019 2:41 pm

Re: Convert long date to YYYYMMDD

Postby Vn5eOJK » Thu Oct 06, 2022 2:35 am

I see now I need to enable date.js in an option menu. I'm sorry, but none of my other reading (including the ECMA Spec) suggested this would be functionality that would need imported from another library.
Vn5eOJK
 
Posts: 11
Joined: Sat Jan 19, 2019 2:41 pm

Re: Convert long date to YYYYMMDD

Postby Admin » Sat Oct 08, 2022 6:15 am

Hi, it could be another issue causing this because this works in BRU without additional JS libraries:

Code: Select all
var rightNow = new Date();
newName = rightNow.toISOString();


What script are you using?

thanks
Admin
Site Admin
 
Posts: 2354
Joined: Tue Mar 08, 2005 8:39 pm


Return to Javascript Renaming