Convert Numeric Date to Written date

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

Convert Numeric Date to Written date

Postby trm2 » Sun Jan 26, 2020 3:18 pm

You did such a great job on a similar question, I would like to post a new topic to get the answer on the reverse:

I would like to be able to take a numeric date and convert it to the written date. This would probably involve some sort of table, as was done wen you provided the answer to
converting high ASCII to Unicode.

Using the same sample in a previous post:

234567890 20200106.pdf to 1234567890 January 6, 2020.pdf

Thanks again!
trm2
 
Posts: 155
Joined: Wed Jan 15, 2020 12:47 pm

Re: Convert Numeric Date to Written date

Postby therube » Sun Jan 26, 2020 8:03 pm

(Oh, I see you saw Reformat Date in File Name.
Was going to say, work backwards ;-).)
therube
 
Posts: 929
Joined: Mon Jan 18, 2016 6:23 pm

Re: Convert Numeric Date to Written date

Postby trm2 » Sun Jan 26, 2020 8:22 pm

Unfortunately, when it comes to javascript, I have to rely on you guys. I like scripts that are universally useful. I am working on something that will benefit others.
So for now I need to ask that these requests be fulfilled by those with far more knowledge.

Thanks in advance.
trm2
 
Posts: 155
Joined: Wed Jan 15, 2020 12:47 pm

Re: Convert Numeric Date to Written date

Postby trm2 » Wed Jan 29, 2020 2:56 pm

Any takers? Admin..?
trm2
 
Posts: 155
Joined: Wed Jan 15, 2020 12:47 pm

Re: Convert Numeric Date to Written date

Postby trm2 » Tue Feb 04, 2020 2:26 pm

Oh come on people, I really would like to have the Javascript so I can use it in my work - so both the convert to and from (previously posted) cycle is complete.
Other people would benefit too, I'm sure. It is probably complex, but I've seen what others have done.
If it can't be done, let it be known so I can move on. Thanks in advance.
trm2
 
Posts: 155
Joined: Wed Jan 15, 2020 12:47 pm

Re: Convert Numeric Date to Written date

Postby Admin » Wed Feb 05, 2020 1:00 am

Code: Select all
function parseyyyymmdd(str) {
    if(!/^(\d){8}$/.test(str)) return "invalid date";
    var y = str.substr(0,4),
        m = str.substr(4,2),
        d = str.substr(6,2);
    return new Date(y,m,d);
}

function getSecondPart(str) {
    return str.split(' ')[1];
}

function getFirstPart(str) {
    return str.split(' ')[0];
}

var d = parseyyyymmdd(getSecondPart(name));

newName = getFirstPart(name) + ' ' + d.toString("MMMM dd, yyyy");

// for all toString formats see: https://github.com/datejs/Datejs


:) sorry for delay
Admin
Site Admin
 
Posts: 1903
Joined: Tue Mar 08, 2005 8:39 pm

Re: Convert Numeric Date to Written date

Postby trm2 » Wed Feb 05, 2020 1:09 pm

Thank You! Worked great.
trm2
 
Posts: 155
Joined: Wed Jan 15, 2020 12:47 pm


Return to Javascript Renaming


cron