Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    compare datetime

    Hi,
    (I'm a beginner)
    could you tell me how to compare two datetime while neglecting hours, min and sec?
    I want to list the items that have a date less than or equal to a date entered by the user
    here is my code :
    Code:
     
    
    isc.DynamicForm.create({
        ID: "RappelsForm",
        width: 300,
        saveOnEnter: true,
        dataSource: crm_objects,
        fields: [
            {name: "crm_obj_dnac",
             title: "later than",
             type: "datetime",
             useTextField: true,
             operator: "lessThan",
             defaultValue: new Date(),
    		}
    		
        ]
    	
    });
    
    isc.IButton.create({
    	ID: "RappelsButton",
    	left: 310,
    	icon: "[SKIN]actions/filter.png",
            title: "Filtrer",
            click: function () {
    		var c ={crm_kind_can_alert:true ,crm_obj_isactive: true};
    		var crit = isc.DataSource.combineCriteria(RappelsForm.getValuesAsCriteria(), c);
    		RappelsGrid.fetchData(crit);
    		
    		
    		
        }
    });

    #2
    You can use Date.createLogicalDate() or date.getLogicalDateOnly()

    Comment


      #3
      date.getLogicalDateOnly()

      date.getLogicalDateOnly() is the right solution but how I'll do it for element of the ListGrid?
      in addition, the comparison is done using the operator "lessThan!
      Have you seen my code?
      Last edited by debutant_ISC; 25 Feb 2014, 05:55.

      Comment


        #4
        Yes we saw the code. Its not clear what you're trying to do, or what you're getting instead. Do you *want* a lessThan criteria? If not, don't specify operator: "lessThan". If you do, you need advancedCriteria. If you want to affect the formItems in a ListGrid's recordEditor or filterEditor, use editorProperties or filterEditorProperties.

        Probably, if you just want to work purely with Dates, you should just set type: "date" rather than "datetime" on your formItems or ListGrid/DS fields

        Otherwise, please try to explain more clearly what you want to do.
        Last edited by Isomorphic; 25 Feb 2014, 06:05.

        Comment


          #5
          I have a ListGrid reminders
          Code:
           isc.ListGrid.create({
              ID: "RappelsGrid",
          	width:850, height:"100%",
          	alternateRecordStyles:true,
              dataSource: crm_objects,
              autoFetchData: true,
              initialCriteria : {crm_kind_can_alert:true , crm_obj_isactive: true},
          	sortField : "crm_obj_dnac",
          	sortDirection: "ascending",
          	fields: [ 
          			{name:"crm_obj_name", title:"Name" ,align: "left" , width:"*"} //Should be on first place  
          			,{name:"crm_obj_desc", title:"Desc." ,width:300, showIf:"true", canEdit:true,  length: 500}
          			,{name:"crm_kind_icon",title:"Icon" ,align:"center",canEdit:false,width:50,type:"image", align:"center", imageURLPrefix:"/portal/app_crm/images/", imageURLSuffix:".png"}
          			,{name:"crm_obj_kind",title:"Kind" ,align:"left",canEdit:false,width:140}
          			,{name:"crm_obj_dnac", title:"Next Act." ,align:"center",canEdit:true,width:120}
          			,{name:"crm_obj_dact", title:"Date Act." ,align:"center",canEdit:true,width:120}
          			,{name:"crm_kin_can_alert", title:"alert" ,align:"center",showIf:"false"}
          			,{name:"crm_obj_isactive", title:"active" ,align:"center",showIf:"false"}
          	]
          	 emptyMessage: " Aucun rappel pour cette date  " 
          })
          , Field to enter the date
          Code:
           
          isc.DynamicForm.create({
              ID: "RappelsForm",
              width: 300,
              saveOnEnter: true,
              dataSource: crm_objects,
              fields: [
          		{	name: "crm_obj_dnac",
          			 title: "later than",
          			 type: "datetime",
          			 useTextField: true,
          			 operator: "greaterThan",//I could not use GreaterThanOrEqual and Equal
          			 defaultValue: new Date()
                  }
              ]
          });
          and a button to filter reminders
          Code:
           
          isc.IButton.create({
          	ID: "RappelsButton",
          	left: 310,
          	icon: "[SKIN]actions/filter.png",
              title: "Filtrer",
              click: function () {
          		var c ={crm_kind_can_alert:true , crm_obj_isactive: true};
          		var crit = isc.DataSource.combineCriteria(RappelsForm.getValuesAsCriteria(), c);
          		RappelsGrid.fetchData(crit);
          				
              }
          });
          I want to filter my list for reminders that have the same date entered by the In User
          Last edited by debutant_ISC; 25 Feb 2014, 06:32.

          Comment


            #6
            Ok.

            1) firstly, what datatype is the underlying data? Is it stored as dates or datetimes? You should indicate this by setting the type attribute on your ListGridFields, and this setting is important for sorting and filtering. If you want to find values that equal other values, use operator: "equals", not "lessThan" or "greaterThan". If you want to provide a range (start and end dates that cover a day, for example), use *both* lessThan and greaterThan in an AdvancedCriteria. See the docs for that if you're not aware of it.

            You can get this automatically by using a DateRangeItem or a MiniDateRangeItem instead of a DateItem (specify editorType: "DateRangeItem").

            2) Whatever your answer to question 1), are you aware of listGrid.showFilterEditor and related APIs? This provides an automatic and configurable filtering mechanism for all filterable fields with no extra code and you could then remove your additional DynamicForm and Button, and your manual fetch code.
            Last edited by Isomorphic; 25 Feb 2014, 06:49.

            Comment


              #7
              yes, I just specify the type in my ListGrid and the data is stored as datetime.
              I Know "advancedCriteria" and listGrid.showFilterEditor but I am obliged to make a form,
              what I'm doing is working at 80%
              but I have 2 problems :
              the first is the operator 'GreaterThanOrEqual "does not work with dates
              the 2nd, I can not use 'equals' because I want to compare the dates (not including hour, min, sec) and I don't know how to do it
              Last edited by debutant_ISC; 25 Feb 2014, 07:02.

              Comment


                #8
                It sounds like you want users to enter a date string without times, but you want to then perform your filtering including the start and end times of the entered day.

                So you want to create two criterions that cover the logical date typed into your FormItem. If so, make the "type" of the FormItem "date" and use the value from the formItem to create two separate datetime values - something like

                Code:
                var start = new Date(enteredYear, enteredMonth, enteredDate, 0, 0, 0);
                var end = new Date(enteredYear, enteredMonth, enteredDate, 23, 59, 59)
                
                var advancedCriteria = { _constructor: "AdvancedCriteria", operator: "and", criteria: [
                    { fieldName: "field", operator: "greaterThanOrEqual", value: startDate },
                    { fieldName: "field", operator: "lessThanOrEqual", value: endDate }
                ] }
                
                grid.filterData(advancedCrit);

                Comment


                  #9
                  thank you !
                  when I get the date entered, I find that format "2014 Tue Feb 25 4:33:15 p.m. GMT +0100 (Paris, Madrid)" and I could not retrieve the day, month and year (with getDay(), getMonth() , getYear())
                  how I can change this format to facilitate the task?
                  I thank you in advance

                  Comment


                    #10
                    Apart from anything else, that's not a logical date (ie, it has a time portion which is not 12 noon) - please check and/or show the code for your dynamicForm as it is now, and the code that gets the value from it.

                    Comment


                      #11
                      here is the code
                      Code:
                      isc.DynamicForm.create({
                          ID: "RappelsForm",
                          width: 300,
                          saveOnEnter: true,
                          dataSource: crm_objects,
                          submit: function () {
                             // RappelsGrid.fetchData({crm_kind_can_alert : true, crm_kind_dnac: RappelsForm.getValue("crm_obj_dnac")});
                      	   // RappelsGrid.filterData(RappelsForm.getValuesAsCriteria());
                          },
                          fields: [
                              {name: "crm_obj_dnac",
                               title: "later than",
                               type: "date",
                               useTextField: true,
                               // operator: "equals",
                      		 defaultValue: new Date()
                              }
                          ]
                      });
                      
                      
                      isc.ListGrid.create({
                          ID: "RappelsGrid",
                      	width:850, height:"100%",
                      	alternateRecordStyles:true,
                          dataSource: crm_objects,
                          autoFetchData: true,
                      	showFilterEditor:true,
                         initialCriteria : {crm_kind_can_alert:true , crm_obj_isactive: true},
                      	sortField : "crm_obj_dnac",
                      	sortDirection: "ascending",
                      	fields: [ 
                      			{name:"crm_obj_name", title:"Name" ,align: "left" , width:"*",canFilter:false} //Should be on first place  
                      			,{name:"crm_obj_desc", title:"Desc." ,width:300, showIf:"true", canEdit:true,  length: 500, canFilter:false}
                      			,{name:"crm_kind_icon",title:"Icon" ,align:"center",canFilter:false, canEdit:false,width:50,type:"image", align:"center", imageURLPrefix:"/portal/app_crm/images/", imageURLSuffix:".png"}
                      			,{name:"crm_obj_kind",title:"Kind" ,align:"left",canEdit:false,width:140, canFilter:false}
                      			,{name:"crm_obj_dnac", title:"Next Act." ,type:"datetime", align:"center",canEdit:true,width:120, canFilter:true}
                      			,{name:"crm_obj_dact", title:"Date Act." ,type:"datetime",align:"center",canEdit:true,width:120, canFilter:false}
                      			,{name:"crm_kin_can_alert", title:"alert" ,align:"center",showIf:"false"}
                      			,{name:"crm_obj_isactive", title:"active" ,align:"center",showIf:"false"}
                      					
                      	],
                      	getCellCSSText: function (record, rowNum, colNum) {
                      			
                      			if ((this.getFieldName(colNum) == "crm_obj_name") || (this.getFieldName(colNum) == "crm_obj_kind")  || (this.getFieldName(colNum) == "crm_obj_desc") ){
                      				// var d = new date();
                      				if (record.crm_obj_isactive == false) {
                      					return "color:red;text-decoration:line-through;font-style:italic;";
                      				}
                      				if((record.crm_obj_dact)){
                      					return "background-color:green;color: white";
                      				}
                      			}
                      			else if ((this.getFieldName(colNum) == "crm_obj_dnac") || (this.getFieldName(colNum) == "crm_obj_dact") ) {
                      					return "color:#C0C0C0;";
                      			}
                      			
                      	},
                      	 emptyMessage: " Aucun rappel pour cette date  " 
                      })
                      
                      
                      isc.IButton.create({
                      	ID: "RappelsButton",
                      	left: 310,
                      	icon: "[SKIN]actions/filter.png",
                          title: "Filtrer",
                          click: function () {		
                      		var d = RappelsForm.getValue("crm_obj_dnac");
                      		isc.say("test date "+ d.getDay);
                          }
                      });

                      Comment


                        #12
                        getDay is a function() - also, you need to do new Date().getLogicalDateOnly() as your default value

                        Comment


                          #13
                          yes yes it's just a typing mistake, getDay () and getMonth() return good values ​​against getYear () retourn 114 instead of 2014
                          that's why I want to change the date format

                          Comment


                            #14
                            ? getYear() is long deprecated - use getFullYear()

                            Comment


                              #15
                              thank you it works!
                              the same problem for getDay it retourn the number of days in the week

                              Comment

                              Working...
                              X