1

This Script date.format.js in http://stevenlevithan.com/assets/misc/date.format.js

 var txt = 04/04;<br/> dateFormat(txt, “dd/mm/yyyy”); 

result : 04/04/2001
I Want Result : 04/04/2013

2
  • 1
    Could you please explain what you are trying to do, what is the output and what you would expect to have? Commented Aug 12, 2013 at 5:29
  • it is browser depended, Chrome converts new Date('04/04') to Wed Apr 04 2001 00:00:00, while FF gives Invalid Date Commented Aug 12, 2013 at 5:34

2 Answers 2

3

You are feeding the function an ambiguous date, don't expect a neat result.

In Firefox, I get "01/01/1970", but if I wrap 04/04 in quotes, so I believe what you I get invalid date, check the js file in line 38 to see why.

What you can do is add the current year pro grammatically like this http://jsfiddle.net/nabil_kadimi/c3Nsf/2/:

var txt = '04/04'; txt += '/' + (new Date()).getFullYear(); window.alert(dateFormat(txt, "dd/mm/yyyy")); 
Sign up to request clarification or add additional context in comments.

2 Comments

How if var txt = '04/04 23:03:00';
Do you mean that you don't knw how txt will be formatted in advance?
0

You would want to read this wonderful article on date parsing idiosyncrasies between various browsers.

There are some rules of the thumb provided for working with dates and also about how Chrome is a more accepting browser than others in terms of date formats.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.