Arcgis Pro - Field Calculator - Change time to 12:00:00AM

1982
10
04-07-2021 10:07 AM
RickeyFight
MVP Regular Contributor

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? 

 

 

0 Kudos
10 Replies
jcarlson
MVP Esteemed Contributor

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

 

- Josh Carlson
Kendall County GIS
RickeyFight
MVP Regular Contributor

@jcarlson 

Thanks for the quick reply. What language is this in Arcade?

When I run the script as arcade it adds one day and sets the time to 7:00:00AM

0 Kudos
jcarlson
MVP Esteemed Contributor

Yes, sorry, it's Arcade. You might be dealing with a time zone offset, it sounds like.

- Josh Carlson
Kendall County GIS
RickeyFight
MVP Regular Contributor

@jcarlson 

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

RickeyFight_0-1617821968687.png

and this is what I get after running the script you suggested 

RickeyFight_1-1617822119705.png

 

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
0 Kudos
DanPatterson
MVP Esteemed Contributor

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

PS

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)

 


... sort of retired...
RickeyFight
MVP Regular Contributor

@DanPatterson 

Unfortunately  I cannot get your suggestions to work. 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Can you elaborate on what isn't working?  Are you getting error messages, unexpected results?

0 Kudos
RickeyFight
MVP Regular Contributor

@JoshuaBixby 

I don't know where to start with Dan's suggestion 

0 Kudos
jcarlson
MVP Esteemed Contributor

Instead of "n" being datetime.now(), replace it with the attribute value of the feature.

- Josh Carlson
Kendall County GIS
0 Kudos