Why is DATEONLY() returning the wrong date?
Hello All,
Does anyone understand the behavior of the highlighted cell below? I believe it should be displaying "08/18/20".
Best Answers
-
Paul Newcome ✭✭✭✭✭✭
Basically the logic behind the solution is pulling the hour then saying that if it is greater than or equal to the hour that starts causing issues (but does not equal twelve) and "pm", then subtract 1 from the date.
I'll take a stab at it even though I haven't gone through my notes yet to at least get you started on the right track.
Pull the Hour:
=VALUE(MID([email protected], 10, FIND(":",[email protected]) - 10))
If the hour is greater than or equal to 7 and does not equal 12 and the time is PM, then subtract 1 from the original date.
=DATEONLY([email protected]) - IF(AND(VALUE(MID([email protected], 10, FIND(":",[email protected]) - 10)) >= 7, FIND("P",[email protected])> 0), 1)
For the above you will need to figure out which hour of the day is where the change needs to start occurring and then change the 7. I just used that as an example. Based on your screenshot it looks like 4pm is good but 9pm is not. You will want to test each of the hours in between to figure out what that number should be.
thinkspi.com
-
L_123 ✭✭✭✭✭✭
My understanding of this is they are on pacific time as smartsheet is based out of seattle. So the datetime in the background is always going to be pacific time, and is converted to local time for the frontend.
Left should work, if it didn't then Paul's solution wouldn't work as it isn't any different than pulling the mid
If you need it in date format you can use something like this
=DATE(VALUE(20 + MID([email protected], 7, 2)), VALUE(LEFT([email protected], 2)), VALUE(MID([email protected], 4, 2)))
Answers
-
Michele Thomas ✭✭✭✭
Hi Brian,
This is an odd thing. Try
=DATEONLY([email protected])
That may help for it to select the correct row...possibly.
-
Brian Cianciolo ✭✭✭
Hi Michele,
Thanks for the suggestion, but that didn't work either.
-
Paul Newcome ✭✭✭✭✭✭
It very possibly has to do with Time Zones. I have seen this a handful of times elsewhere throughout this Community. If you do a search for posts related to time zones you should be able to find a few different options for solutions.
thinkspi.com
-
Brian Cianciolo ✭✭✭
谢谢保罗,我一定能看到这一点as being the issue. I'll try to do some more testing and let you know what I find.
-
Paul Newcome ✭✭✭✭✭✭
Basically the logic behind the solution is pulling the hour then saying that if it is greater than or equal to the hour that starts causing issues (but does not equal twelve) and "pm", then subtract 1 from the date.
I'll take a stab at it even though I haven't gone through my notes yet to at least get you started on the right track.
Pull the Hour:
=VALUE(MID([email protected], 10, FIND(":",[email protected]) - 10))
If the hour is greater than or equal to 7 and does not equal 12 and the time is PM, then subtract 1 from the original date.
=DATEONLY([email protected]) - IF(AND(VALUE(MID([email protected], 10, FIND(":",[email protected]) - 10)) >= 7, FIND("P",[email protected])> 0), 1)
For the above you will need to figure out which hour of the day is where the change needs to start occurring and then change the 7. I just used that as an example. Based on your screenshot it looks like 4pm is good but 9pm is not. You will want to test each of the hours in between to figure out what that number should be.
thinkspi.com
-
Brian Cianciolo ✭✭✭
Wow thanks Paul! This solution seems to do the trick (after I tune in the time values, of course). I do have a question about it: does "=LEFT([email protected],8)" do the trick or is there an instance where that wouldn't work?
-
L_123 ✭✭✭✭✭✭
My understanding of this is they are on pacific time as smartsheet is based out of seattle. So the datetime in the background is always going to be pacific time, and is converted to local time for the frontend.
Left should work, if it didn't then Paul's solution wouldn't work as it isn't any different than pulling the mid
If you need it in date format you can use something like this
=DATE(VALUE(20 + MID([email protected], 7, 2)), VALUE(LEFT([email protected], 2)), VALUE(MID([email protected], 4, 2)))
-
Paul Newcome ✭✭✭✭✭✭
@[email protected]I feel like this had been tried in a previous post and it was still pulling the wrong date because of how it was stored on the back-end. That's why I went with the solution I used. My solution mostly ignores the date by looking at the time instead.
thinkspi.com
-
L_123 ✭✭✭✭✭✭
I see what you are saying, I didn't look closely enough at your formula. Yeah I would double check to make sure that the left actually does correctly populate.
We really need some major enhancements to time functionality in smartsheet....
-
Stefan ✭✭✭✭✭✭
Yes, time zone handling in Smartsheet really needs a global solution!
Smartsheet Consulting, Solution Building, Training and Support.
Projects for Processes and for People.
-
BD ✭
Hello@Brian Cianciolo.你的解决方案使用左边的功能吧k? Currently this is my workaround, but, I was curious to see if you had any issues using the Left Function. Thank you.
-
Brian Cianciolo ✭✭✭
Hi@BD.The left solution is working fine for me. If there is an instance where it hasn't worked; I have yet to notice it.
-
BD ✭
Thanks Brian.
In the end, I had to use the below formula from Paul above in order to get =yearday function to work. . Thanks Paul.
=DATEONLY([email protected]) - IF(AND(VALUE(MID([email protected], 10, FIND(":",[email protected]) - 10)) >= 7, FIND("P",[email protected])> 0), 1)
-
Paul Newcome ✭✭✭✭✭✭
-
I am in Pacific Time Zone and am running into the same issue with DATEONLY().
After some trial and error I found the date to be off by 7 hours, so the DATEONLY() will give the date at 0:00 GMT.
I added another AND() expression to@Paul Newcome's formula to account for this but also to account for the 12pm hour.
=DATEONLY([email protected]) - IF(AND(VALUE(MID([email protected], 10, FIND(":",[email protected]) - 10)) >=5,VALUE(MID([email protected], 10, FIND(":",[email protected]) - 10)) < 12, FIND("P",[email protected]) > 0), 1)
If it doesn't work for you, just try adjusting the number in the first expression (5 in my example)
Hope that helps.
Help Article Resources
Categories
Check out theFormula Handbook template!
=([Contract amount]@row - [Install Labor (actual)]@row) \/ [Contract amount]@row<\/p>
Be sure the \"Percentage\" column is formatted as a percentage. Positive numbers show that your total spend is under<\/strong> the [Contract amount]. Negative values show your total spend is over<\/strong>.<\/p>
You can use a similar formula to measure how far over\/under your [Labor $ (quoted)] amount is from your [Install Labor (actual)] amount.<\/p>
=([Labor $ (quoted)]@row - [Install Labor (actual)]@row) \/ [Labor $ (quoted)]@row<\/p>
Here, though, a negative value shows that you are OVER<\/strong> the estimate. A positive value shows you are at or UNDER<\/strong> the estimate.<\/p>