Solved

problem with dates

Posted on 2001-06-18
4
181 Views
Last Modified: 2013-12-18
hello experts,
  i put textbox and change the field properties as datetime.when i run this in notes client its working fine.the same when i run this on web calender type is not coming.i dont want to user should select the dates from the control not by typying manually. and one more thing is i want to calculate difference in dates.if it is greater than 21 days it should give message that diff should be less than 21 days.how to do this.is there any inbuilt control is there.


waiting for answer.
0
Comment
Question by:shaikhidayat
  • 2
4 Comments
 
LVL 4

Expert Comment

by:sloeber
Comment Utility
Shaikidayat,

You can't use the popup calendar screen on the web.
If you want to use a popup calendar tool for selecting dates, you must write it down in Java.


About the time difference.
Do you want the formula for calculating the difference or do you want the formula for the popup or both
?
When must it check the dates, on the moment the user enter a date or every day?
Do you have on your form two date fields, or do you have one time field and the other time field is
today.

For showing a message screen on the web you use alert("text")

Greets,
Sloeber

0
 
LVL 13

Expert Comment

by:CRAK
Comment Utility
The datepicker is also available in javascript!
0
 

Author Comment

by:shaikhidayat
Comment Utility
hello sloeber,

i want the date popup should work on the web.so what should i write in java or javascript.

reg the difference in dates

i want to calculate the difference in dates when the user select two dates from two date fileds.

if the diff is greater than 21 days it should give me alert.

how can i do it.
0
 
LVL 13

Accepted Solution

by:
CRAK earned 30 total points
Comment Utility
In a hotspot's onClick-event:

putcal(document.forms[0],'myDtFieldName')

In the form's HTML head content:

//globals
var month;
var day;
var year;  
var delim = new Array(":","/","\\","-"," ",".");
var monthArray = new Array(0,31,29,31,30,31,30,31,31,30,31,30,31);

function getMonth_and_Date(form,fieldName){
      //get the date month and year from de field and parse them to the variables day month and year

      dtString = eval("form." + fieldName + ".value");
      // trim date string
      while ((dtString.charAt(0) == " ") && (dtString.length != 0))
            dtString = dtString.substring(1,dtString.length - 1)
      while ((dtString.charAt(dtString.length - 1) == " ") && (dtString.length != 0))
            dtString = dtString.substring(0,dtString.length - 1)
      //get date components
      i = 0; startPos = 0;      pos = 0;
      //get day
      do {
            pos = dtString.indexOf(delim[i], startPos);
            i++
            }
      while ((pos == -1) && (i < delim.length));
      day  = parseInt(dtString.substring(startPos,pos),10);
      startPos = pos + 1;

      //get month
      i = 0;
      do {
            pos = dtString.indexOf(delim[i], startPos);
            i++
            }
      while ((pos == -1) && (i < delim.length));
      month  = parseInt(dtString.substring(startPos,pos),10);
      startPos = pos + 1;

      //get year
      year = parseInt(dtString.substring(startPos,dtString.length),10)
      year = (year <= 100) ? 1900 + year : year;

}
//end function getMonth_and_Date

function validateDate(form, fieldName){
      // get the date from the form  
      getMonth_and_Date(form,fieldName);

      // check if the entered date is a number
      if (isNaN(month)) return false;
      if (isNaN(day)) return false;
      if (isNaN(year)) return false;

      // check if the entered dateparts are valid
     if ((month < 1) || (month > 12)) return false;
      if ((day < 1) || (day > monthArray[month])) return false;

      if ((month == 2) && (day == 29)){
                  if ( (year%4) !== 0)       return false;      
      }
      // all checks have been passed the date is valid
      return true
}
//end function validateDate

function alertInvalidDate( fieldName, fieldLabel){
      //alert the user that entered date is invalid
      alert('De datum in het veld "' + fieldLabel + '" is niet geldig');
      eval("document.forms[0]."+fieldName+".focus()");
      eval("document.forms[0]."+fieldName+".select()");
}
//end function alertInvalidDate

function getToday(){
      //get todays date and parse it to the vars day month and year

      today = new Date();
      day = today.getDate();
      month = today.getMonth();
      month++;
      year = today.getYear();
      year = (year <= 100) ? 1900 + year : year;
}
//end function getToday

function putcal(form, dateFieldName) {
      // show the calendar in a new window

      // check if the entered dat is valid if not replace it with today
      if(!validateDate(form, dateFieldName)) getToday();

      // open the calendar in a new window
      var version = navigator.appVersion;
      if (navigator.appVersion.indexOf("Mac") != -1) {
            calwin = open("","calwin","width=300,height=300,resizable=yes");
      } else {
            calwin = open("","calwin","width=230,height=240,resizable=yes");
      }
      calccal(calwin,form,dateFieldName);
}
//end function putcal

function calccal(targetwin,form,dateFieldName) {
  //calculate and write the calendar window

  var monthname = new Array(12);
  monthname[0] = "January";
  monthname[1] = "February";
  monthname[2] = "March";
  monthname[3] = "April";
  monthname[4] = "May";
  monthname[5] = "June";
  monthname[6] = "July";
  monthname[7] = "August";
  monthname[8] = "September";
  monthname[9] = "October";
  monthname[10] = "November";
  monthname[11] = "December";

  var endday = calclastday(eval(month),eval(year));

  mystr =  month + "/01/" + year;
  mydate = new Date(mystr);
  firstday = mydate.getDay();

  var cnt = 0;

  var day = new Array(6);
  for (var i=0; i<6; i++)
    day[i] = new Array(7);

  for (var r=0; r<6; r++)
  {
    for (var c=0; c<7; c++)
    {
      if ((cnt==0) && (c!=firstday))
        continue;
      cnt++;
      day[r][c] = cnt;
      if (cnt==endday)
        break;
    }
    if (cnt==endday)
      break;
  }

 // start writing the calendar
 targetwin.document.open()
 targetwin.document.writeln("<HEAD><STYLE>A:link{text-decoration:none};A:hover{color:red};TD {font: 13pt Arial;}</STYLE></HEAD>")
 targetwin.document.writeln("<FORM><TABLE><TR VALIGN=TOP>");

  // create the next and previous buttons
  var prevyear = eval(year) - 1;
  targetwin.document.writeln("<TD><INPUT TYPE=BUTTON NAME=prevyearbutton VALUE='<<'"+
   " onclick='opener.month = " + month + "; opener.year = " + prevyear + ";document.clear();opener.calccal(opener.calwin,opener.document." + form.name + ",\"" + dateFieldName + "\")'></TD>");

  var prevmonth = (month == 1) ? 12 : month - 1;
  var prevmonthyear = (month == 1) ? year - 1 : year;
  targetwin.document.writeln("<TD><INPUT TYPE=BUTTON NAME=prevmonthbutton VALUE='&nbsp;<&nbsp;'"+
   " onclick='opener.month = " + prevmonth + "; opener.year = " + prevmonthyear + ";document.clear();opener.calccal(opener.calwin,opener.document." + form.name + ",\"" + dateFieldName + "\")'></TD>");

  targetwin.document.writeln("<TD COLSPAN=3 ALIGN=CENTER>");
  var index = eval(month) - 1;
  targetwin.document.writeln("<B>" + monthname[index] + " " + year + "</B></TD>");

  var nextyear = eval(year) + 1;      
  var nextmonth = (month == 12) ? 1 : month + 1;
  var nextmonthyear = (month == 12) ? year + 1 : year;
  targetwin.document.writeln("<TD><INPUT TYPE=BUTTON NAME=nextmonthbutton VALUE='&nbsp;>&nbsp;'"+
   " onclick='opener.month = " + nextmonth + "; opener.year = " + nextmonthyear + ";document.clear();opener.calccal(opener.calwin,opener.document." + form.name + ",\"" + dateFieldName + "\")'></TD>");

  targetwin.document.writeln("<TD><INPUT TYPE=BUTTON NAME=nextyearbutton VALUE='>>'"+
  " onclick='opener.month = " + month + "; opener.year = " + nextyear + ";document.clear();opener.calccal(opener.calwin,opener.document." + form.name + ",\"" + dateFieldName + "\")'></TD>");
 
  // start writing the calendar days
  targetwin.document.writeln("</TR><TR>");
  targetwin.document.writeln("<TD>Su</TD>");
  targetwin.document.writeln("<TD>Mo</TD>");
  targetwin.document.writeln("<TD>Tu</TD>");
  targetwin.document.writeln("<TD>We</TD>");
  targetwin.document.writeln("<TD>Th</TD>");
  targetwin.document.writeln("<TD>Fr</TD>");
  targetwin.document.writeln("<TD>Sa</TD>");
  targetwin.document.writeln("</TR>");

  targetwin.document.writeln("<TR><TD COLSPAN=7><HR NOSHADE></TD></TR>");
  targetwin.document.writeln("<TR><TD COLSPAN=7><TABLE  WIDTH=\"100%\" BORDER=\"0\">");

  var selectedmonth = eval(month) - 1;
  var today = new Date();
  var thisyear = today.getYear() + 1900;
  var selectedyear = eval(year) - thisyear + 4;

  var conditionalpadder = "";

  for(r=0; r<6; r++)
  {
   targetwin.document.writeln("<TR>");
   for(c=0; c<7; c++)
   {
    targetwin.document.writeln("<TD>");
    if(day[r][c] != null) {
      if (day[r][c] < 10)
        conditionalpadder = "&nbsp;"
      else
        conditionalpadder = "<!!>";
                  targetwin.document.writeln("<a href=\"javascript:window.close();" +       
                  "opener.document." + form.name + "." + dateFieldName + ".value = '" + day[r][c] + "-" + month + "-" + year + "'" +
                  "\">" + conditionalpadder + day[r][c] + conditionalpadder +  "</a>")
    }
    targetwin.document.writeln("</TD>");
   }
   targetwin.document.writeln("</TR>");
  }
  targetwin.document.writeln("</TABLE></TABLE></FORM>");
  targetwin.document.close()
}
//end function callccal


function calclastday(month,year) {
  if ((month==2) && ((year%4)==0))
    return 29;

  if ((month==2) && ((year%4)!=0))
    return 28;

  if ((month==1) || (month == 3) || (month == 5) || (month == 7) ||
      (month==8) || (month == 10) || (month ==12))
    return 31;

  return 30;
}
//end function calclastday

function calcnextmonth(month) {
  if (month=="12")
   return "1";

  else
    return (eval(month)+1);
}
//end function calcnextmonth

function calcnextyear(month,year) {

 if (month=="12")
    return (eval(year)+1);
  else
    return (year);
}
//end function calcnextyear

function calcprevmonth(month) {
  if (month=="1")
    return "12";
  else
    return (eval(month)-1);
}
//end function calcprevmonth

function calcprevyear(month,year) {
  if (month=="1")
    return (eval(year)-1);
  else
    return (year);
}
//end function calcprevyear
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now