Solved

Format date

Posted on 2014-02-06
5
371 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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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)

808 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