-1

I have two date controls. When the page loads, I have to set end date as current date and start date as one week from current date. How to do this? I have to use only JavaScript. How to populate these two controls when the page loads?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Vinodh
  • 1
  • 1
  • Duplicate of [How do I get the current date in JavaScript?](https://stackoverflow.com/q/1531093/215552) and [how to get next week date in javascript](https://stackoverflow.com/q/1025693/215552) – Heretic Monkey Jan 06 '23 at 23:11
  • Does this answer your question? [how to get next week date in javascript](https://stackoverflow.com/questions/1025693/how-to-get-next-week-date-in-javascript) – Heretic Monkey Jan 06 '23 at 23:11

2 Answers2

-1

take a look at this : http://keith-wood.name/datepick.html

his documentation has almost everything covered.

you'll definitely feel at ease with this tool..

Shrinath
  • 7,888
  • 13
  • 48
  • 85
  • and if your problem was only related to converting dates, then download dateJS and use it. – Shrinath Feb 07 '11 at 10:13
  • no. i already have the calendar control. How to populate the start and end date on page loading, with end date as today's date and start date as one week before current date. – Vinodh Feb 07 '11 at 10:17
  • just add the date as "value" into the text box in the exact format the calendar gives you... :) for easy manipulation of dates, you could work your way with http://www.w3schools.com/js/js_obj_date.asp or use dateJS – Shrinath Feb 07 '11 at 10:24
  • I mean like this : or whatever weird format your calendar is currently programmed to display.. – Shrinath Feb 07 '11 at 10:26
  • @Vinodh : and which calendar control are you using by the way – Shrinath Feb 07 '11 at 10:30
  • @Shrinath : i'm using calendar control in sap. Here you have hard coded the value of date, but i dont want to hard code. It has to be fetched. – Vinodh Feb 07 '11 at 10:43
  • @Vinodh : I was answering with jquery calendar in mind, my mistake..! why don't you simulate the click event with those dates ? – Shrinath Feb 07 '11 at 10:57
  • @Shrinath : i'm not that much good working in html pages, that is the reason i'm struggling a bit. I've written on page_load function : document.getElementById("testinput2").value=Date(); This gets me the value as Mon Feb 02/07/2011 where as the possible input can only be 02/07/2011. – Vinodh Feb 07 '11 at 11:09
  • @Vinodh : use this : `var date = new Date(); var today = date.getMonth()+1 + "/" + date.getDate() + "/" + date.getFullYear(); document.getElementById("testinput").value=today;` read it from here : http://jsfiddle.net/tTgqH/ – Shrinath Feb 07 '11 at 11:29
  • This is a link to an answer, not an answer. [Edit] it to include the relevant information from your conversation. – Heretic Monkey Jan 06 '23 at 23:08
-1

You can use Date() javascript object.

// current date
var currentDate = new Date();
var time = currentDate.getTime();
KomarSerjio
  • 2,861
  • 1
  • 16
  • 12