11

I have a Date string of following format:

'31-OCT-2013'

How do I convert this into Date of following format using Extjs 4:

'08/31/2013'

I am using IE8.

István
  • 5,057
  • 10
  • 38
  • 67
user204069
  • 1,215
  • 3
  • 19
  • 25

2 Answers2

17

If you have string "31-OCT-2013", you need to:

Convert it into date object

var myDate = Ext.Date.parse("31-OCT-2013", 'd-M-Y');

Format it to as you want

Ext.Date.format(myDate, 'm/d/Y');
Sivakumar
  • 1,477
  • 2
  • 18
  • 35
6

Try something like this:

If your day representation would be 2 digit with leading zero, then apply this

var date = Ext.Date.parse("31-OCT-2013", 'd-M-Y');
console.log(Ext.Date.format(date, 'm/d/Y'));

But if your day representation would be without a leading zero, then apply this

var date = Ext.Date.parse("31-OCT-2013", 'j-M-Y');
console.log(Ext.Date.format(date, 'm/d/Y'));

Check the docs for Ext.Date

fujy
  • 5,168
  • 5
  • 31
  • 50
  • 1
    Pretty sure you want Ext.Date.parse('31-OCT-2013', 'd-m-Y'). 'd/m/y' is the output format, 'd-m-Y' is the input. Also, it's hard to tell from the example, but if the day portion uses only a single digit for days 1-9, he should swap 'j' in for the 'd'. Right on for the output formatting though. – Stephen Tremaine Nov 06 '13 at 03:18