JavaScript - Javascript Dates
Can anyone explain why this isn't working!? I hate JavaScript and dates! For the date: 07/08/2010 it will output: 6/7/2010.
Thanks for any help. Code: var startDay = startDate.value.substr(0,2); var startMonth = startDate.value.substr(3,2); var startYear = startDate.value.substr(6,4); var myDate = new Date(startYear,startMonth-1,startDay+numberNights.value); endDate.value = myDate.getDay() + '/' + myDate.getMonth() + '/' + myDate.getFullYear(); Similar TutorialsHi, I have a problem related to Javascript. 1) I have a php form in which there two text boxes. 2) User enter date in these text boxes via using a calender control. 3) Dates displayed in the textbox in this format i.e: 05-11-2009 I need to compare the dates of both text boxes, but my code is not working fine. I think i need to convert these the values of both text boxes to date format, but i am unable to do this. Can anyone please help in writing the new code. Thanks Hi so because the jquery range slider has no date range ability and because the only date range plugin for jquery UI sliders is very bloated and fails to work on modern ipad / new touch event methods... I'm writing my own today.. Can some one better exmplain to me how to do: "theCurrentDate (05/12/2012) - anOlderDate (05/12/1990) = difference of how many days is?" and "theCurrentDate (05/12/2012) - 200 = but resulting in date formatted version, not some 9394829398 number"? Thanks! I am trying to launch an HTML page with a calendar field populated with today's date. I have a function to set the date but I am getting an error when I try to run the page: Code: //Begin function window_onload function window_onload() { UpdateData(); // TODO: Add your event handler code here function onInitialUpdate() { document.getElementById('calendar1').value=getTodaysDate(); } } //End function window_onload function getTodaysDate(){ var today = new Date(); var dd = today.getDate(); var mm = today.getMonth()+1; var yyyy = today.getFullYear(); if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm} var today = yyyy+'/'mm+'/'+dd; alert('Today is '+mm+'/'+dd+'/'+yyyy); return today; } gives me an error that the onload function is expecting an object. Is ther something wrong with my coding? Hi there How can you calculate the difference in two dates that are in different formats? I have one date as: '2010-06-16 21:20:44.000' and the other date as now = new Date(); I want to subtract the dates to see if it is over 30 days. Thanks! I'm not sure if java is the best way to go with this, I'm pretty inexperienced with java, but I have a workable knowledge of html, and couldn't see a way to do it that way... so here goes: For my job I work with a ton of different deadlines all the time. What I want to do is to make a webpage that displays the date N days ago, and N days into the future. So something like 7 days ago, 30 days ago, 60 days ago 75 days ago, 30 days from now, 60 days from now, 75 days from now. etc. I've found brief snippets for how to display today's date, but i'm having trouble with the calculations. Then I also need one that displays 18 years ago, I'm not sure if the change from days to years makes any kind of difference, but I suppose it's easy enough to convert years to days anyway.... How would I go about doing that? Thank you!!! I have 2 dates in variables (formatted like 'Wed Jan 18 2012 01:01:01 GMT+0000 (BST)') I need to minus them to get the days This worked if they were in the same month var amountOfDays = date.getDate() - datefirst.getDate(); However if the dates where in 2 different months it doesnt work. How would i do it better 2 months? Hi Guys I have created a flight/hotel itinerary and I need to work out the duration of the customers' holiday in order to work out how much it will cost to charge that person per night at their selected hotel. The problem I have is that the dates are going to vary due to user inputs in which I have used jquery 's " datepicker " Cheers George Hello, I'd like to be able to calculate the difference between 2 dates in the format dd/mm/yyyy var date1 = 06/01/2012 var date2 = 10/01/2012 Then an alert box would tell me there is a difference of 4 days. Thanks a bunch Jay. Hi I have the following script Code: function timeDifference(laterdate,earlierdate) { var difference = laterdate.getTime() - earlierdate.getTime(); var daysDifference = Math.floor(difference/1000/60/60/24); difference -= daysDifference*1000*60*60*24 document.write('difference = ' + daysDifference + ' day/s '); } var laterdate = ? ; var earlierdate = ? ; timeDifference(laterdate,earlierdate); //--></script> and would like to insert my datein and dateout values where the ? marks are above in red. I can call these variables into the form on the page using <%=Request("datein")%> but how do I call a variable into the script above ? Thanks Calculating the difference between two dates in JavaScript is relatively straightforward, provided you choose the right Date methods to work with. Whichever way you get there.... see this http://www.tutorials99.com/tutorials...aScript/page_1 I really don't understand JavaScript... xD Code: var inputDate = "<?php echo $inputDate2; ?>"; var JDates = new Array(); Jdates = inputDate.split("/"); var currentDate = new Date(parseInt(Jdates[2]), parseInt(Jdates[0])-1, parseInt(Jdates[1])); So... when creating 'currentDate' Jdates[0] will equal 0, even though I just asked javascript to split the inputDate by all "/". The inputDate var equals "08/06/2010" before the split. Any help greatly appreciated! This is my problem: I have a seperate page on my website with a list of upcoming events. On that page I have the date of the upcoming event and then the description. On the main page of my website, I have a small table with the next four upcoming events(with the dates of course). So far I have been manually changing the four closest upcoming events on the main page. (just copy and paste from the upcoming events page) My question: Can javascript "grab" from the upcoming events page the next four events, and have them automatically pasted into the table on my main page? And if it is possible, what code(s) do I need? This way I don't have to do it manually and will save me lots of time. P.S. I have a weak understanding of javascript, but throw any code at me and I will try to understand it. Thank you Hi I'm relatively new to Javascript and I'm trying to learn more about dates my problem is as follows I have to do validation on a form for 2 dates(StartDate and EndDate) the dates cannot be more than four months apart if they are an alert must be displayed. In other words Nov 2009 till March 2010 or May 2009 till September 2009 should be invalid regardless of the day of the month Simply 2 input boxes(StartDate and EndDate) and a submit I've got the other parts of my page worked out just this has me stumped I would appreciate any help in this regard Thank You for your time Hi- I am new to this so, please forgive me in advance... goldDaysArray[3] = new Date(); goldDaysArray[3].setFullYear(2010,01,01); goldDaysArray[4] = new Date(); goldDaysArray[4].setFullYear(2010,01,03); goldDaysArray[5] = new Date(); goldDaysArray[5].setFullYear(2010,01,22); goldDaysArray[6] = new Date(); goldDaysArray[6].setFullYear(2010,01,09); Can the three .setFullYear statements be combined into one, so I can reduce the number of statements? There are many more. I tried: goldDaysArray[3] = new Date(); goldDaysArray[3].setFullYear(2010,01,[01,03,22,09]); but February 1 was not recognized. Can someone please help? Thank you. Hi Javascript Gurus, I've made a webpage which displays a list of timeslots in GMT time, and also conveniently displays the GMT times in the clients local time, depending on the timezone they have on their comp. The output on my computer (Melbourne +10 GMT) is perfect. It even anticipates a future Daylight Savings change. It looks like this: Code: Option 1: Saturday 24th Oct 20:00 GMT = YOUR time: Sunday, October 25, 2009 7:00:00 AM Option 2: Saturday 24th Oct 22:00 GMT = YOUR time: Sunday, October 25, 2009 9:00:00 AM Option 3: Saturday 24th Oct 24:00GMT = YOUR time: Sunday, October 25, 2009 11:00:00 AM Option 4: Sunday 25th Oct 20:00GMT = YOUR time: Monday, October 26, 2009 7:00:00 AM Option 5: Sunday 25th Oct 22:00 GMT = YOUR time: Monday, October 26, 2009 9:00:00 AM Option 6: Sunday 25th Oct 24:00 GMT = YOUR time: Monday, October 26, 2009 11:00:00 AM BUT when I switch my computer to a North American, or European time (to test) the Saturday times are one hour later than the Sunday ones!?! Here's an example (Central US time -6 GMT): Code: Option 1: Saturday 24th Oct 20:00 GMT = YOUR time: Saturday, October 24, 2009 3:00:00 PM Option 2: Saturday 24th Oct 22:00 GMT = YOUR time: Saturday, October 24, 2009 5:00:00 PM Option 3: Saturday 24th Oct 24:00GMT = YOUR time: Saturday, October 24, 2009 7:00:00 PM Option 4: Sunday 25th Oct 20:00GMT = YOUR time: Sunday, October 25, 2009 2:00:00 PM Option 5: Sunday 25th Oct 22:00 GMT = YOUR time: Sunday, October 25, 2009 4:00:00 PM Option 6: Sunday 25th Oct 24:00 GMT = YOUR time: Sunday, October 25, 2009 6:00:00 PM Daylight Savings happens in the US in November, so what's going on? thanks, Andrew K Hello there, plz help working with php. am new to coding. I am working to get a reservation system for golf tee times. I have 2 different pages. one is where i will set the generic settings for golf course. the other is a reservations page which provides an option to add new reservation page. Now in the settings page i can set no of days to 1 thru 5. it will be inserted into config table in database. Based on this, on reservation page, i need to show only 1 or 2 or 5 days on the popup calendar starting from today which allows to select one while making new reservation. or based on the setting if i can prepopulate those dates in a drop down list on the addreservation.php Hey guys. I need little bit of help which i know it will be piece of cake for you. In emp_rota.php , i want the user to select multiple dates (through a calendar) which will be fetched in the php in the next page. everything works except that the calendar script works only on DATE1, when user clicks to add another date then though everything works , except the calendar doesnt come up. help MEE !! P.s. i am attaching the whole script along with this http://www.mediafire.com/?ayz7mpiauba4dya I have a javascript controlling the display of a DIV that I did a while back that needs a bit more tweaking to add function to hide the DIV on specific holidays. As it is now, by default, the DIV is being hidden unless it is M-F between 8:00AM-6:00PM: Code: <script type="text/javascript"> onload=function(){ var rightNow = new Date(); var day = rightNow.getDay(); var hour = rightNow.getHours(); var minute = rightNow.getMinutes(); var formDisplay = 'none'; // unless we see otherwise var forwardDisplay = 'block'; // unless we see otherwise if(day==1 || day==2 || day==3 || day==4 || day==5) { // if chat is avalable on these days if((hour>=8) && (hour<=17)) // if chat is avalable between these times formDisplay = 'block', forwardDisplay = 'none'; } document.getElementById('ChatForm').style.display = formDisplay; document.getElementById('ChatForward').style.display = forwardDisplay; } </script> Im assuming that I would just add more else if statements, but not really sure the cleanest way to assign specific dates using this format. Any help is appreciated Hi there, Where I work there are certain dates where nothing can be done, certain times where work can be done with caution, and dates where work can be done. I want to put on the site a traffic light that would change colours based on the calendar dates where work can/can't be done. For example, if April 11th there is stuff to do, the traffic light would be green. But April 12th, there isn't work to do, it would turn red. Do you know how I would go about doing this? Hello! I am trying to find a script that allows you to open multiple browser tabs and then close each of those tabs, either one by one or all at once. Does anyone know how to do this please? Thanks so much for your help. |