-1
{$userinfo.create_account_date}

This returns me date in the following format: Oct-3-2017

I want to parse it to: DD/MM/YYY (03/10/2017)

The source code is encrypted. Is there a way to parse it through front-end only?

Pyromonk
  • 684
  • 1
  • 12
  • 27
Maverickk
  • 33
  • 4
  • `front-end only` would make this not a PHP question. – chris85 Oct 10 '17 at 03:22
  • possible duplicate of [javascript-change-date-into-format-of-dd-mm-yyyy](https://stackoverflow.com/questions/13459866/javascript-change-date-into-format-of-dd-mm-yyyy) – Shadow Fiend Oct 10 '17 at 03:26
  • If you just want a string to display, you can reformat it using string methods quite easily. What have you tried? Where did you have trouble? – RobG Oct 10 '17 at 03:33
  • No code to look at and OP asks for an answer any one know how read minds ? – S4NDM4N Oct 10 '17 at 04:38

2 Answers2

1

Front-end, assuming JavaScript. In most simple style.

function reformatDate(datumStr) {
  var monthsArr = [];
  monthsArr['Jan'] = '01';
  // add missing months here
  monthsArr['Oct'] = '10';

  var dArr = datumStr.split('-');
  return [dArr[1], monthsArr[dArr[0]], dArr[2]].join('/');
}
console.log(reformatDate('Oct-3-2017'));

Output:

3/10/2017

Addition to Karen's comment below.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function reformatDate(datumStr) {
  var monthsArr = [];
  monthsArr['Jan'] = '01';
  // add missing months here
  monthsArr['Oct'] = '10';

  var dArr = datumStr.split('-');
  return [dArr[1], monthsArr[dArr[0]], dArr[2]].join('/');
}

function elRfr(idName, datumStr) {
            var id = document.getElementById(idName);
            id.innerHTML = reformatDate(datumStr);
}
</script>
</head>
<body>
<div id="ourDate"><script type="text/javascript">elRfr('ourDate', 'Oct-3-2017');</script></div>
</body>
</html>

Karen, this is simplified example with just one DIV. In your case you should replace 'Oct-3-2017' with {$userinfo.create_account_date}, I guess. If I assume correctly that your code is Salesforce Apex code.

svujic
  • 114
  • 6
  • sorry for my lack of knowledge. But how do I implement it? I've put you're code into my `scripts.js` file. Now i have an HTML with `Date: {$userinfo.create_account_date}` What changes do I have to make on this HTML? – Maverickk Oct 10 '17 at 05:39
  • You should not use an Array like a plain Object. – RobG Oct 10 '17 at 09:06
  • @RobG You are right, but what is the real problem in this concrete example? – svujic Oct 10 '17 at 10:05
-2

Create a new var, initialize the date string as a new Date:

var d = new Date('Oct-3-2017');

Then manipulate it however you want with Date methods.

Chase
  • 3,009
  • 3
  • 17
  • 23