ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

How to get today date


#12

@max_morais_dmm, where to put this? I puy it in default value under Customize Form but it thrown error…

Cab you help with example? Thnks a lot


#13

Why you don’t use “Credit Days” functionality? You can define Credit Days in Customer record.


#14

If you are customising a form and wants to set default value for date field to today then use “Today” in default section.


#15

@jof2jc you need put it in a custom script!

frappe.ui.form.on('Sales Order', 'onload', function(frm){
    frm.set_value("delivery_date", frappe.datetime.add_days(frappe.datetime.nowdate(), 20));
})

#16

@max_morais_dmm Hi I would really appreciate your help with this. Can I fetch the number of days to add in field from a custom field? Let’s say I would like to enter the credit days manually in each sales, so I did this:

  1. add customer field called “credit_days”
  2. fetch it into the field from customer master like this to retrieve the standard credit days;

cur_frm.add_fetch(‘customer’,‘credit_days’,‘credit_days’)

  1. Add this script to calculate, but it adds 20 days as it was intended from your post.

frappe.ui.form.on(‘Sales Invoice’, ‘onload’, function(frm){
frm.set_value(“due_date”, frappe.datetime.add_days(frappe.datetime.nowdate(), 20));
})

Now it would be awesome if you could help change the script to fetch the days to add from the credit days field which is populated automatically from the customer master, but needs to be changed case by case, so when changed it calculates the new due date based on that field.

I am thankful for your help.
Mo


#17

@mrmo this post will provide to you the knowledge for you achive you requirement


#18

@max_morais_dmm @nabinhait Hi again, I tried to check that post but I don’t see a way to update the date according to the value in custom field.
What I would like to do is enter for example 40 days in custom field ‘credit_days’ and after that the “payment due date field” should add 40 days to its current date.

frappe.ui.form.on(‘Sales Invoice’, ‘onload’, function(frm){
frm.set_value(“due_date”, frappe.datetime.add_days(frappe.datetime.nowdate(), row.credit_days));
})

I really appreciate your help, thank you.


#19

@mrmo, define your logic based on customer field change!

You can achive this, because you dont have the customer while onload, so you cant call the server to get the credit_days from the customer.


#20

@max_morais_dmm I am thankful for your help, maybe I have explained it wrong, let me try again.
I would like to add days based on days that I input in the custom field on the sales invoice document, which I call credit days. I am sorry for the confusion, below is a picture with screenshot for your reference, thank you so much.


#21
frappe.ui.form.on('Sales Invoice', 'credit_days', function(frm){
frm.set_value("due_date", frappe.datetime.add_days(frappe.datetime.nowdate(), frm.doc.credit_days));
})

Quick question. Default datetime sliders to certain parameters
#22

@max_morais_dmm I am very thankful for your help, you are awesome!
When I am finished with this customization project, I will share all for the rest to enjoy.
Thank you!


#23

Hello,

How to get month’s first date for report module ?

Thanks,
Hardik Gadesha


#24

@Hardik_Gadesha try with frappe.datetime.month_start()


How to get day from date in frappe?
#25

Where can I find documentation on frappe.datetime methods?


#26

Hi, @tmatteson!

frappe.utils.data and frappe.datetime have similar methods. You can find the documentation for frappe.utils in: https://frappe.github.io/frappe/current/api/utils/frappe.utils.data

However, we’re both in the same boat. I haven’t found the documentation for frappe datetime methods. I usually just rely on Pycharm’s autocomplete and code suggestion feature. :slight_smile: Sometimes, I run console on chrome or firefox just to figure out the different frappe methods.

Hope it helps.

Cheers!

Hera


#27

hi all

iv done the above steps while im trying to update item delivery date in sales order

i`v created a custom field in item and sales order item called delivery_days and fetched it successfully by

cur_frm.add_fetch(“item_code”,“delivery_days”,“delivery_days”);

and tried the followign script

frappe.ui.form.on(‘Sales Order Item’, ‘delivery_days’, function(frm){
frm.set_value(“delivery_date”, frappe.datetime.add_days(frappe.datetime.nowdate(), frm.doc.delivery_days));
})

it makes the item delivery date today not today + frm.doc.delivery_days

whats wrong with that ??


#28

so sorry about repost

but i really need this script ASAP


#29

Hey @Mahmoud_Ghoneem

The frappe.datetime.nowdate() and frappe.datetime.add_days are python/ server side code, so they won’t work in your javascript. Sorry, and I understand your confusion about it.

Frappe uses the moment library for client side datetime functionality. The documentation you need to do this is there. https://momentjs.com/docs/#/displaying/to/


#30

Thanks for your reply

but actually its working when i use th following code in custom script for sales order item

frappe.ui.form.on(‘Sales Order Item’, ‘delivery_days’, function(frm){
frm.set_value(“delivery_date”, frappe.datetime.add_days(frappe.datetime.nowdate(), 12);
})

and it works fine Today+12 Day

but actually what i need is to get custom field (delivery_days) instead of 12

what should i do ??


#31

Expected input: delivery days = 12;
Expected output: delivery date = today + delivery_days;

Break this into two lines of code and console.log the intermediate step.

Look for frappe.utils.data.formatdate in the docs, I think that may be where you’re stuck.