Hi Folks
Following is my use case
i am creating a custom doc type and i have a column date in my doc type and i want to default this date by incremental hours and or days based on certain condition , both side of conditions
for e.g. If A=B th then date must be previous date+2 hours
and if C=D then date must be previous date+2 days
Can anyone suggest , how can i achieve this with examples if any ?
Rgds
O
When do you want the date updated? When the doctype is created or everytime something changed on the doctype?
For client-side you can refer to this link for the datetime utils that you can use:
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
frappe.provide("frappe.datetime");
frappe.defaultDateFormat = "YYYY-MM-DD";
frappe.defaultTimeFormat = "HH:mm:ss";
frappe.defaultDatetimeFormat = frappe.defaultDateFormat + " " + frappe.defaultTimeFormat;
moment.defaultFormat = frappe.defaultDateFormat;
frappe.provide("frappe.datetime");
$.extend(frappe.datetime, {
convert_to_user_tz: function (date, format) {
// format defaults to true
// Converts the datetime string to system time zone first since the database only stores datetime in
// system time zone and then convert the string to user time zone(from User doctype).
let date_obj = null;
if (frappe.boot.time_zone && frappe.boot.time_zone.system && frappe.boot.time_zone.user) {
date_obj = moment
This file has been truncated. show original
you need somethings like this:
var current_datetime = frappe.datetime.now_datetime();
if(C=D){
var added_datetime = frappe.datetime.add_days(current_date,2)
}
for adding hours you’ll probably have to read the momentjs documentations