Compairing Dates Like 08/29/2007 To 08/30/2007
Aug 29, 2007
is there a way to compare dates/times using javascript that are already coded to output like this: 08/29/2007 8:30 to 08/30/2007 10:00
Var CurrentDateTime output: "MM/DD/YYYY HH:MM"
I am trying to find a way to calculate if the deadline for a project has passed, and have been stuck on the if statement, since you cant really compare variables that have slashes, spaces, and colons in them... or can you?
View 1 Replies
ADVERTISEMENT
Feb 16, 2007
I have a simple HTML page that calls a .js file. This runs with no problem on my laptop but has issues on my desktop PC. My desktop has Norton Internet Security 2007. I have read that NIS may have ad blocking quirks that alter javascript code. I do not see any undesired code in my HTML page when I right-click and "View Source". The script works fine if I include it directly in the HTML file.
Here is the .js code
function greetGuest()
{
alert("Welcome to the JavaScript development site");
}
function getName(ctrl)
{
var guestName = prompt("Please enter your name. "); //get the guest's name
document.getElementById(ctrl).value = guestName; //transfer guest name to txt1
}
function changeBackground(ctrl)
{
var select = document.getElementById(ctrl);
var index = select.selectedIndex;
var selectedTxt = select.options[index].text;
var selectedVal = select.options[index].value;
var msg = "The " + (index+1) + " option is selected.
";
msg += "It is the option " + selectedTxt;
msg += " and has the value " + selectedVal + ".";
msg += " Is this correct?";
var confirmVal = confirm(msg);
if (confirmVal == true)
{
switch(selectedVal)
{
case "black":
document.body.text="white";
document.body.bgColor=selectedVal;
break;
case "white":
document.body.text="black";
document.body.bgColor=selectedVal;
break;
default:
document.body.text="black";
document.body.bgColor=selectedVal;
break;
}
}
}
Here is the HTML page.
<!--
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Test Page 1</title>
<script type="text/javascript" src="testScript.js"></script>
</head>
<body onload="greetGuest();">
<p>
<input type="button" name="btn1" value="Press me greeting" onclick="getName('nameBox');" />
<input type="text" name="nameBox" id = "nameBox" value=" " size="30" /> </p>
<center>
<p>Select a background color</p>
<p><select name="selectColors" id = "selectColors" onChange="changeBackground('selectColors');">
<font color="aqua">
<option value="aqua">AQUA</font></option>
<font color="black">
<option value="black">BLACK</font></option>
<font color="blue">
<option value="blue">BLUE</font></option>
<font color="fuschia">
<option value="fuschia">FUSCHIA</font></option>
<font color="gray">
<option value="gray">GRAY</font></option>
<font color="green">
<option value="green">GREEN</font></option>
<font color="lime">
<option value="lime">LIME</font></option>
<font color="maroon">
<option value="maroon">MAROON</font></option>
<font color="navy">
<option value="navy">NAVY</font></option>
<font color="olive">
<option value="olive">OLIVE</font></option>
<font color="purple">
<option value="purple">PURPLE</font></option>
<font color="red">
<option value="red"></font>RED</option>
<font color="light blue">
<option value="silver">SILVER</font></option>
<font color="light blue">
<option value="teal">TEAL</font></option>
<font color="light blue">
<option value="white"></font>WHITE</option>
<font color="light blue">
<option value="yellow">YELLOW</font></option>
</select></p>
</center>
</body>
</html>
-->
I hope this doesn't come out looking funny. My question is, does anyone know what could cause this phenomenon?
Again. On the laptop it works either in script or as a src file. On desktop it only works in script tags.
View 1 Replies
View Related
Jun 8, 2010
So I'm writing an application in Adobe Air (AJAX) and I've come upon a little problem.
I've created a function to set a minimum size for the window
var check_size = function() {
if ( window.nativeWindow.width < 690 ) {
window.nativeWindow.width = 690;
}
[code]...
View 4 Replies
View Related
Aug 30, 2010
where I can get a Date and Time Picker that will only allow to choose current dates instead of past dates written in Javascript or JQuery?
View 5 Replies
View Related
Jul 23, 2005
This problem seems to occur dependant on the computer system settings.
I have no issues when the system date is set as M/d/yyyy but I do
have a problem with the system date set as d/M/yyyy.
I have a text box on a web page that holds the date ie)
document.frmTimesheet.tWeekFrom.value = 19/12/2004
theDate = new Date(document.frmTimesheet.tWeekFrom.value);
// split into day, month, year
iDay = theDate.getDate();
iMonth = theDate.getMonth()+1;
iYear = theDate.getFullYear();
alert(iDay);
alert(iMonth);
alert(iYear);
iday= 12
iMonth= 07
iYear= 2005
View 10 Replies
View Related
Jul 23, 2005
I am currently using a function to validate a form on the client side
(see code below). At the end of the function, I would like it to also
compare a startDate against an endDate to ensure that the endDate is
greater than (comes after) the startDate. The date format I'm using is
MM/DD/YYYY and it's writing to an MS SQL Server 2000 database table
via ASP. Code:
View 2 Replies
View Related
Jul 23, 2005
I want to obtain the user's current age by comparing their date of birth
(user inputs) to the current date.
I know how to get the Current Date but I'm not finding how to calculate the
Current Date minus the User's Birthday.
It would be something like yourage = curdate - bday;
I will then use the results to determine if the User is Over 21 or Under 21.
I'm going nuts trying to figure this out.
Is there an Easier Book to learn this stuff other than the "Begining
JavaScript 2nd Edition". Code:
View 9 Replies
View Related
Jul 28, 2005
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine:
function compareDate(a,b)
{
var date_a = new Date(a);
var date_b = new Date(b);
if (date_a < date_b)
{ return -1; }
else
{
if (date_a > date_b)
{ return 1; }
else
{ return 0; }
}
}
I guess it expects the date in mm/dd/yyyy format.
Do I have to change:
var date_a = new Date(a);
var date_b = new Date(b);
so it recognizes a correct format?
View 22 Replies
View Related
Jul 20, 2005
I have a successful script for determining today's date. Does anyone have anything for determining tomorrow and the next day since it would have to look at the day of month and month of year?
View 8 Replies
View Related
May 15, 2007
A HTML Form has 2 sets of 3 dropdown select lists. The 1st set is for users to enter the start time & the 2nd set is for users to enter the end time. The 1st dropdown select list in both the sets is where users will select hours, the 2nd dropdown select list in both the sets is where users will select minutes (the 2nd dropdown select list in both the sets have 4 options - 00, 15, 30 & 45). The 3rd dropdown select list in both the sets is where users will select either AM or PM.
Now it's quite obvious that the start time can come after the end time (on the same date). For e.g. you can't let users select the start time as 9:00 AM & the end time as 6:00 AM.
How do I validate that the end time always comes after the start time & vice-versa?
View 2 Replies
View Related
May 1, 2010
Here is my problem, I am trying to get the difference of two different date. I want to get how much hour and second is their different. My problem is the 1st date is using a different format this is the example:2010-05-01 13:46:04 the second one is I am trying to get the today's time and date by using this code: "currentTime.getTime()". Here is my whole code
[Code]...
View 5 Replies
View Related
Jun 1, 2009
I would like to know how to achieve this. I want to know the difference between two dates in months, how much days left over, and how much hours left over. I do not need days or hours equivalent to the months remaining. The problem is I also want it to consider February's less than 30 days and 29 days in leap year. I spend my entire week trying to figure out how to do it.
In the end I want values in variable months_left, days_left, and hours_left. I tried modifying several date deference scripts but I couldn't get them to work as intended.
View 3 Replies
View Related
Jul 23, 2005
For my website i would like to display the age of my son in years,
months, days and hours.
For now i manage to get a result for totals. Like the total number of
days.
This is the beginning:
starttime = Date.parse("Aug 10,2003, 07:07")
sdt = new Date(starttime)
starttime= Math.ceil((starttime) / 1000 / 60 / 60 / 24 )
ndt = new Date()
y = sdt.getYear()
m = sdt.getMonth() + 1
d = sdt.getDate()
h = starttime
View 26 Replies
View Related
Jul 23, 2005
I'd like to add an automatically updating date field to a webpage. I found the below example on the internet which works brilliantly except I'd like an ordinal date (e.g. 1st, 2nd, 3rd, 4th)
instead of a cardinal date (e.g. 1, 2, 3, 4).
How could I do that with this small bit of javascript code?
<script language = "JavaScript">
var now = new Date();
var monNames = new
Array("January","February","March","April","May","June","July","August","September","October","November","December");
document.write("Last updated: " + now.getDate() + " " +
monNames[now.getMonth()] + " " + now.getFullYear());
</script>
View 12 Replies
View Related
Jul 23, 2005
I've written several scripts that have "while" blocks which increment a
date by one day if the date does not match one of a group of dates.
However, sometimes it apparently steps out out the while loop even
though my condition isn't met. Will work for a few loops then steps out
often.
Are there javascript "date" issues? I have also noticed different
results between Firefox and Internet Explorer.
View 11 Replies
View Related
Oct 20, 2005
Have two text form with dates i need to compare before submitting, the
second should always be a date later the first one.
Anyone have a script for this?
View 9 Replies
View Related
Nov 10, 2006
I have two date fields (check in, check out) and "number of days"
field.
I want the script to calculate automatically the difference.
For example: I have defaults dates, and I want the script to put the
difference in "number of days" field. And if the user will change the
date, the number of days will change automatically.
View 1 Replies
View Related
Apr 13, 2010
I am using the standard datepicker but it has been highly modified to meet our needs. We have an option to select an entire week of dates:
[Code]..
What I'm trying to do is retrieve the first date of that selected week and the last date. All attempts have failed.
View 3 Replies
View Related
May 25, 2011
How do I get the difference in days between 2 dates using Javascript?
View 1 Replies
View Related
Jan 26, 2009
I'm trying to get a select box to automaticly populate the year ranging from 2008 to the current year + two years.Below I've put the code I've got so far which populates it with the current year plus two years so for example at the moment it shows 2009, 2010 & 2011. Next year it would show 2010, 2011, 2012 but I need it to start at 2008 so this year it would show 2008, 2009, 2011 & 2012 and next year 2008, 2009, 2011 & 2012.
Code:
<script type="text/javascript">
var year = new Date();
var nextYear = year.getFullYear()+1;
var nextYear2 = year.getFullYear()+2;
[code]....
View 1 Replies
View Related
Jul 10, 2009
Here is my dilemna. I know HTML...and that's about it. So someone decided to give me a project that involves JavaScript. i've been reading tutorials online as much as possible...but I am a way beginner - be soft on me.
I have a form that had many drop down boxes. When a user selects a specific request type it populates the standard turnaround time in business days.
I need the "Standard Delivery Date" box to then autopopulate today's date plus the standard turnaround time that pops up in that field. How??
Here is a code that I have been working on - but so far it's not working.code...
View 11 Replies
View Related
Jul 21, 2009
i have found one, and its close to it and need a little tweak to work on second textbox
<script language="JavaScript">
<!--
function addDays(myDate, days){
[code].....
i have two input textbox for dates, one is date borrowed which from date picker calendar 07/21/2009 and what i would like to make is the second textbox would be auto compute for X months meaning the second input textbox whould display a value = 01/21/2010 if i assign a 6 months variable
View 1 Replies
View Related
Dec 9, 2009
I have the following script
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?
View 4 Replies
View Related
Nov 3, 2010
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
View 4 Replies
View Related
Mar 5, 2011
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. code...
View 2 Replies
View Related
Sep 15, 2010
So I'm supposed to be using a form to get the date of Easter or Ash Wednesday and return the other. It should also check that the date for Easter is a Sunday and the date for Ash Wednesday is indeed on Wednesday. What I have so far isn't working. I'm not sure what I'm doing wrong. I know my if...else logic isn't going to work right since I've assigned new Date () to easter and ash. How to clean this up and get it working right?
<html>
<head>
<title>Ash Wednesday to Easter Sunday</title>
<script type="text/javascript">
<!--
var ash = new Date();
var easter = new Date();
var temp;
var month = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
function convMonth (){
}function fnAshToEaster (){
ash.setDate(document.formAshToEaster.ashDate.value);
ash.setMonth(document.formAshToEaster.ashMonth.value);
ash.setYear(document.formAshToEaster.ashYear.value);
easter.setDate(document.formAshToEaster.easterDate.value);
easter.setMonth(document.formAshToEaster.easterMonth.value);
easter.setYear(document.formAshToEaster.easterYear.value);
if (ash == "") .....
View 7 Replies
View Related