Hybrid View

  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    1
    Vote Rating
    0
    mehdi ben njima is on a distinguished road

      0  

    Default calculate the number of days and months between two dates

    calculate the number of days and months between two dates


    hello
    I tryto find the numberof months,daysandhoursbetween twodateswithextjs!
    I haveaproblemin my code!

    Code:
    {    //Lbl_Date_Heure_Effet
                    x: 10,
                    y: 85,
                    xtype: 'label',
                    cls: 'x-abs-required-layout-item',
                    text: currentFichePoliceCorpsLabels.Lbl_Date_Heure_Effet + " :"
                },
                {
                    x: 120,
                    y: 85,
                    xtype: 'label',
                    id: CurrentSheetID + '_poli_date_effet_label',
                    text: Format_Date(currentFichePoliceCorps.poli_date_effet)
                },
                {
                    x: 120,
                    y: 80,
                    xtype: 'datefield',
                    hidden: ((currentFichePoliceCorps.nbr_note_debit > 0  ,
                    allowBlank: false,
                    width: 140,
                    value: currentFichePoliceCorps.poli_date_effet,
                    maxValue : currentFichePoliceCorps.poli_date_fin,
                    format: GlobalListLabels.Format_Date_Time,
                    id: CurrentSheetID + '_poli_date_effet',
                    listeners:
                    {
                        blur: function(elem) 
                        {
                            if (elem.isValid()) 
                            {
                                if(elem.getValue() != null && elem.getValue() != "")
                                {
                                    Ext.getCmp(CurrentSheetID + "_poli_date_fin" ).setMinValue ( elem.getValue() );
                                }
                                 if(elem.getValue() != null && elem.getValue() != "" && Ext.getCmp(CurrentSheetID + "_poli_date_fin" ).getValue() != "" && Ext.getCmp(CurrentSheetID + "_poli_date_fin" ).getValue() != null)
                                {
                                    var m = (Ext.getCmp(CurrentSheetID + "_poli_date_fin" ).getValue().getFullYear() - elem.getValue().getFullYear()) * 12 + (Ext.getCmp(CurrentSheetID + "_poli_date_fin" ).getValue().getMonth() - elem.getValue().getMonth());
                                    Ext.getCmp(CurrentSheetID + '_poli_nb_mois').setValue(m);
                                
                                    var j = (Ext.getCmp(CurrentSheetID + "_poli_date_fin" ).getValue().getFullYear() - elem.getValue().getFullYear()) * 365 + (Ext.getCmp(CurrentSheetID + "_poli_date_fin" ).getValue().getDay() - elem.getValue().getDay());                              
                                    Ext.getCmp(CurrentSheetID + '_poli_nb_jours').setValue(j);
                                    Ext.getCmp(CurrentSheetID + '_poli_nb_jours_12m').setValue(j);
                                    
                                    var h = (Ext.getCmp(CurrentSheetID + "_poli_date_fin" ).getValue().getFullYear() - elem.getValue().getFullYear()) * 8760 + (Ext.getCmp(CurrentSheetID + "_poli_date_fin" ).getValue().getHours() - elem.getValue().getHours());
                                    Ext.getCmp(CurrentSheetID + '_poli_nb_heures').setValue(h); 
                                }
                            }
                        }
                    }
                },
                {    //Lbl_Date_Heure_Fin
                    x: 10,
                    y: 110,
                    xtype: 'label',
                    cls: 'x-abs-required-layout-item',
                    text: currentFichePoliceCorpsLabels.Lbl_Date_Heure_Fin + " :"
                },
                {
                    x: 120,
                    y: 110,
                    xtype: 'label',
                    id: CurrentSheetID + '_poli_date_fin_label',
                    text: Format_Date(currentFichePoliceCorps.poli_date_fin)
                },
                {
                    x: 120,
                    y: 105,
                    xtype: 'datefield',
                    hidden: pasModifiable,
                    width: 140,
                    allowBlank: false,
                    value: currentFichePoliceCorps.poli_date_fin,
                    minValue : currentFichePoliceCorps.poli_date_effet,
                    hidden: ((currentFichePoliceCorps.nbr_note_debit > 0,
                    format: GlobalListLabels.Format_Date_Time,
                    id: CurrentSheetID + '_poli_date_fin',
                    listeners:
                    {
                        blur: function(elem) 
                        {
                            if (elem.isValid()) 
                            {
    
    
                                if(elem.getValue() != null && elem.getValue() != "")
                                {
                                    Ext.getCmp(CurrentSheetID + "_poli_date_effet" ).setMaxValue ( elem.getValue() );
                                }
                                if(elem.getValue() != null && elem.getValue() != "" && Ext.getCmp(CurrentSheetID + "_poli_date_effet" ).getValue() != "" && Ext.getCmp(CurrentSheetID + "_poli_date_effet" ).getValue() != null)
                                {
      var m = (elem.getValue().getFullYear ()- Ext.getCmp(CurrentSheetID + "_poli_date_effet" ).getValue().getFullYear ()) * 12 + (elem.getValue().getMonth ()- Ext.getCmp(CurrentSheetID + "_poli_date_effet" ).getValue().getMonth ());
                                    Ext.getCmp(CurrentSheetID + '_poli_nb_mois').setValue(m);
                                    
                                    var j = (elem.getValue().getFullYear ()- Ext.getCmp(CurrentSheetID + "_poli_date_effet" ).getValue().getFullYear ()) * 365 + (elem.getValue().getMonth ()- Ext.getCmp(CurrentSheetID + "_poli_date_effet" ).getValue().getMonth ());
                                    Ext.getCmp(CurrentSheetID + '_poli_nb_jours').setValue(j);                      
                                    var h = (elem.getValue().getFullYear ()- Ext.getCmp(CurrentSheetID + "_poli_date_effet" ).getValue().getFullYear ()) * 8760 + (elem.getValue().getMonth ()- Ext.getCmp(CurrentSheetID + "_poli_date_effet" ).getValue().getMonth ());
                                    Ext.getCmp(CurrentSheetID + '_poli_nb_heures').setValue(h);
                                    
                                    
                                }
                                
                            }
    
    
                        }
                    }
                }
    thank you for correcting me

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,714
    Vote Rating
    438
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    Convert the two dates to unix timestamp, subtract one from another and that gives you the number of seconds. Then do some more math to convert that to days/months.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.