Solved

Format date

Posted on 2014-02-06
5
375 Views
Last Modified: 2014-02-06
Hi,

var TodayDate = new Date();
var SetDate =(TodayDate .getMonth()+1) + '/' + TodayDate .getDate() + '/' +
        TodayDate .getFullYear();
$("#GetDateFrom").val(SetDate );

I need to format the value in the GetDateFrom field to mm dd yyyy.

Thanks,
0
Comment
Question by:lulu50
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:David Kroll
ID: 39838908
0
 

Author Comment

by:lulu50
ID: 39839000
dkrollCTN,

I want it to display the date like this 02/06/2014

but now it display the date like this 2/6/2014
0
 
LVL 11

Expert Comment

by:David Kroll
ID: 39839021
var TodayDate = new Date();
var SetDate =(TodayDate .getMonth().ToString()+1) + '/' + TodayDate .getDate().ToString() + '/' +
        TodayDate .getFullYear();
$("#GetDateFrom").val(SetDate );
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 total points
ID: 39839307
try this:

var TodayDate = new Date();

var theMonth = TodayDate .getMonth()+1;
if( theMonth < 10 )   theMonth = '0' + theMonth ;

var theDay = TodayDate .getDate();
if( theDay < 10 )        theDay = '0' + theDay;


var SetDate =theMonth + '/' + theDay + '/' + TodayDate .getFullYear();
$("#GetDateFrom").val(SetDate );

Open in new window

0
 

Author Closing Comment

by:lulu50
ID: 39839328
THANK YOU!!!!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question