So I have some old data that has time in the date field. I do not want time in the date field.
I know that I can set the time to 12:00:00AM to make the time disappear from the field.
I need a way to update all the records (different days) to have the same time of day but keep the original date.
Any suggestions on how to do this?
You just need to pull out parts of the date first, then build the new timestamp using the Date function.
var oldDate = $feature["sale_date"] var y = Text(oldDate, 'Y') var m = Text(oldDate, 'MM') var d = Text(oldDate, 'DD') var newDate = Date(y, m, d, 0) return newDate
I got the time to display right by changing to 17 for time. But it keeps adding a month to the calculated value.
this is what my field looks like
and this is what I get after running the script you suggested
var oldDate = $feature.reinspect_date var y = Text(oldDate, 'Y') var m = Text(oldDate, 'MM') var d = Text(oldDate, 'DD') var newDate = Date(y, m, d, 17) return newDate
I will let you get rid of the fluff.. Example using universal format for "now"
from datetime import datetime n = datetime.now() new_n = n.replace(hour=12, minute=00) new_n datetime.datetime(2021, 4, 7, 12, 0, 11, 262084)
Datetime has a "replace" option
Almost forgot... you can use it to see how things will be in the future... like next year 😉
future = n.replace(minute=00, hour=12, second=00, year=2022, month=4, day=7) future datetime.datetime(2022, 4, 7, 12, 0, 0, 262084)