Time Difference custom Field

Dears i need an easy way to fulfill my need

i made a new doctype and named it Feed

i create a three filed in it

starttime --------- type time
endtime ----------- type time
difference ---------- type time

i need the filed difference= endtime - starttime
For example

if starttime = 02:00:20
endtime = 04:20:20

difference = 2:20

Exactly What i need to fulfil is to know how much time i spend
by using this equoation .

is there a way to make a custome script ? and choose my doctype feed against it ?

best regards

Any help dears ?

i will look, just a moment

1 Like

Thank u brother waiting your help

This is my attempts
1- the doctype name is feed

frappe@erpnext:~/frappe-bench/apps/erpnext/erpnext/healthcare/doctype/feed/

2- i edit the file feed.py

-- coding: utf-8 --

Copyright © 2018, Frappe Technologies Pvt. Ltd. and contributors

For license information, please see license.txt

from future import unicode_literals
import frappe
from frappe.model.document import Document

class Feed(Document):
def validate(self):

import frappe.utils

time_diff=frappe.utils.data.time_diff(self.endtime,self.starttime,)
self.difference=time_diff

But i didnt see any progress
Notes the three fileds
starttime
endtime
difference
all those type Date

@sheno did you try

self.save()

at the end of your code?

1 Like

-- coding: utf-8 --

Copyright © 2018, Frappe Technologies Pvt. Ltd. and contributors

For license information, please see license.txt

from future import unicode_literals
import frappe
from frappe.model.document import Document

class Feed(Document):
def validate(self):

import frappe.utils

time_diff=frappe.utils.data.time_diff(self.endtime,self.starttime,)
self.difference=time_diff

self.save()

Nothing happen dear

ah you want to put the code in feed.py?
thats not a custom script, but its also possible.

could you please insert your code here in a format which allows me to read it correct?
e.g.:

class Feed(Document):
    def validate(self):
        and so on...

then i can maybe say you whats wrong…

actually dear
i want to be a custom script because
it will easy for me to understand as i am not a coder
but after i searched a lot i find some guy say we have to put in doctyp.py
so i try his method but didnt work

so if it possible to be a custom script it will be so great and awsome

my need is

i need to get a number wich resemble the differnce between

Two time fileds

starttime ---- type time
endtime ----- type time
difference type (?) should it be Time Or data Or integer ??

the equoation aim mainly to get how many minute the difference between the start and the end time

for example

starttime 2:20:01
endtime 2:40:02
difference = (endtime-starttime)= 20 minute

i need to make it easy as possible to understand it and can fulfil it .

thanks brothers for your help/

@sheno this customscript should work:

frappe.ui.form.on('ToDo', {
     refresh: function(frm) {
		var start = frm.doc.starttime.split(":");
		var end = frm.doc.endtime.split(":");
		var date1 = new Date(2000, 0, 1,  start[0], start[1]); 
		var date2 = new Date(2000, 0, 1, end[0], end[1]); 

		if (date2 < date1) {
			date2.setDate(date2.getDate() + 1);
		}

		var diff = date2 - date1;
		var msec = diff;
		var hh = Math.floor(msec / 1000 / 60 / 60);
		msec -= hh * 1000 * 60 * 60;
		var mm = Math.floor(msec / 1000 / 60);
		msec -= mm * 1000 * 60;
		var ss = Math.floor(msec / 1000);
		msec -= ss * 1000;
		
		frm.set_value('difference', hh+":"+mm+":"+ss);
	 }
});
2 Likes

Dear Joelios
i will try it now and feed u back.

you have to change “ToDo” to your Doctype! :wink:

1 Like

should i use differnce type as a time or as int or as a data filed ?

i wrote this customscript for:
starttime --> time
endtime --> time
difference --> time

1 Like

i will try it now dear
and feed u back

Dear Joelios

u did it man
really i am so so thankful for u .

1 Like

you’re welcome :wink:

1 Like