-1

In Javascript I want to be able to create a string for a date. I would like to use the format

dd-MMM-yyyy
  • I would like the dd part to change between 1 and 29 every time I create the variable (I'm using a loop)
  • the MMM is set to Jan
  • the yyyy to 1999

Can someone help by giving me advice on how I can do this?

padarom
  • 3,529
  • 5
  • 33
  • 57
  • 2
    Have you tried anything yet? If so, can you post your "broken code"? – El Guapo Jul 01 '14 at 17:04
  • 1
    Yes, please share what applicable code you have so far. Thank you. – 2540625 Jul 01 '14 at 17:06
  • possible duplicate of [Where can I find documentation on formatting a date in JavaScript](http://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) – Codeman Jul 01 '14 at 17:06
  • 1
    [How to search](http://stackoverflow.com/help/searching) – tenub Jul 01 '14 at 17:07

2 Answers2

1
var formatted_date = Math.floor(Math.random() * 29) + 1 + '-Jan-1999';
  console.log(formatted_date);
Max Gram
  • 685
  • 4
  • 14
-1

You can do several things.

Check out 10 ways to format date and time using Javascript.

Another set of examples here.

Community
  • 1
  • 1
Codeman
  • 12,157
  • 10
  • 53
  • 91