# Datetime.FromString

**URL:** <https://forum.xojo.com/t/datetime-fromstring/57888>\
**Category:** General\
**Created:** [October 13, 2020, 2:45pm UTC](https://forum.xojo.com/t/datetime-fromstring/57888 "2020-10-13T14:45:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giacomo\_Bernardi](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Giacomo\_Bernardi](https://forum.xojo.com/u/Giacomo_Bernardi)\
**Post date:** [October 13, 2020, 2:45pm UTC](https://forum.xojo.com/t/datetime-fromstring/57888/1 "2020-10-13T14:45:28Z")

</div>

I’m working with 2019r3.1

Dim d As DateTime = DateTime.FromString(“1977-05-23”)

> works fine

Dim d As DateTime = DateTime.FromString(“1977-05-22”)

> causes a RuntimeException: “Parse error: date needs to be in the format of YYYY-MM-DD HH:MM or YYYY-MM-DD”

I have tried other dates, without errors.  
So far, it seems that the only problem is with the date that I have indicated above.

can someone explain me?  
thank you.

---

<div class="post-metadata">

**Author:** ![Jeannot\_Muller](https://forum.xojo.com/user_avatar/forum.xojo.com/jeannot_muller/32/13359_2.png) [@Jeannot\_Muller](https://forum.xojo.com/u/Jeannot_Muller)\
**Post date:** [October 13, 2020, 2:54pm UTC](https://forum.xojo.com/t/datetime-fromstring/57888/2 "2020-10-13T14:54:05Z")

</div>

Works for me. Perhaps a copy and paste and something “wrong” in the quotes or the quotes themselves?

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [October 13, 2020, 2:55pm UTC](https://forum.xojo.com/t/datetime-fromstring/57888/3 "2020-10-13T14:55:51Z")

</div>

Select the string including the quotes in the ide, then right click “clean invisble characters”

The string may be corrupted (for example on copy and paste)

---

<div class="post-metadata">

**Author:** ![Jeannot\_Muller](https://forum.xojo.com/user_avatar/forum.xojo.com/jeannot_muller/32/13359_2.png) [@Jeannot\_Muller](https://forum.xojo.com/u/Jeannot_Muller)\
**Post date:** [October 13, 2020, 2:58pm UTC](https://forum.xojo.com/t/datetime-fromstring/57888/4 "2020-10-13T14:58:47Z")

</div>

Hah! Didn’t know this one yet, good one. Always copying into Sublime Text and back 🙂

---

<div class="post-metadata">

**Author:** ![Giacomo\_Bernardi](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Giacomo\_Bernardi](https://forum.xojo.com/u/Giacomo_Bernardi)\
**Post date:** [October 13, 2020, 3:56pm UTC](https://forum.xojo.com/t/datetime-fromstring/57888/5 "2020-10-13T15:56:02Z")

</div>

thank you for your support.

I had tried with Xojo 2019r3.1 on Windows 10: I confirm that it still does not work.

then I tried with Xojo 2019r3.1 on Windows 10 (Parallel VM on Mac): it works.

finally I tried with Xojo 2020r1.2 on Mac: it doesn’t work.

I don’t understand.

---

<div class="post-metadata">

**Author:** ![Paul\_Lefebvre](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_lefebvre/32/3152_2.png) [@Paul\_Lefebvre](https://forum.xojo.com/u/Paul_Lefebvre)\
**Post date:** [October 13, 2020, 4:15pm UTC](https://forum.xojo.com/t/datetime-fromstring/57888/6 "2020-10-13T16:15:01Z")

</div>

Could this be a localization/language issue? Does the Parallels VM have different settings from the systems where it fails?

---

<div class="post-metadata">

**Author:** ![Giacomo\_Bernardi](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Giacomo\_Bernardi](https://forum.xojo.com/u/Giacomo_Bernardi)\
**Post date:** [October 13, 2020, 4:29pm UTC](https://forum.xojo.com/t/datetime-fromstring/57888/7 "2020-10-13T16:29:45Z")

</div>

I will check the settings well, but I ask myself: why is May 22 fails and May 23 works?  
in this behavior localization/language can be important?

keep in mind that I’m working with thousands of different dates and this seems to be the only date with problems.

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [October 13, 2020, 4:48pm UTC](https://forum.xojo.com/t/datetime-fromstring/57888/8 "2020-10-13T16:48:27Z")

</div>

I can’t make the date crash. Using macOS Catalina with Xojo 2020r1 and Italian language.

---

<div class="post-metadata">

**Author:** ![Giacomo\_Bernardi](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Giacomo\_Bernardi](https://forum.xojo.com/u/Giacomo_Bernardi)\
**Post date:** [October 13, 2020, 5:40pm UTC](https://forum.xojo.com/t/datetime-fromstring/57888/9 "2020-10-13T17:40:30Z")

</div>

I understand that the problem I’ve described may seem at least strange, perhaps not very credible.  
I’ve made several tests before writing here.  
I will carefully check the settings of the environments I’ve listed and I will update you.  
thank you.

---

<div class="post-metadata">

**Author:** ![Jeannot\_Muller](https://forum.xojo.com/user_avatar/forum.xojo.com/jeannot_muller/32/13359_2.png) [@Jeannot\_Muller](https://forum.xojo.com/u/Jeannot_Muller)\
**Post date:** [October 13, 2020, 5:50pm UTC](https://forum.xojo.com/t/datetime-fromstring/57888/10 "2020-10-13T17:50:29Z")

</div>

Nope, no worries - interesting issue. Did you try your code with a simple newly created Desktop App, or are you running this code in a larger app? It would be good to create a new app, with nothing else than your sample code and check if that one fails as well or not.

---

<div class="post-metadata">

**Author:** ![Giacomo\_Bernardi](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Giacomo\_Bernardi](https://forum.xojo.com/u/Giacomo_Bernardi)\
**Post date:** [October 13, 2020, 6:11pm UTC](https://forum.xojo.com/t/datetime-fromstring/57888/11 "2020-10-13T18:11:02Z")

</div>

sorry, I had forgotten these details.  
it is a webapp.  
after the first attempts with my project, for the other tests that i described above, I simply created a new application, inserting that code in the Session.Open event.

---

<div class="post-metadata">

**Author:** ![Giacomo\_Bernardi](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Giacomo\_Bernardi](https://forum.xojo.com/u/Giacomo_Bernardi)\
**Post date:** [October 13, 2020, 7:31pm UTC](https://forum.xojo.com/t/datetime-fromstring/57888/12 "2020-10-13T19:31:05Z")

</div>

![image](https://forum.xojo.com/uploads/default/original/2X/d/d78a40380f92a16ec45eb615181ef0ca823b94b0.png)

a screenshot from a new desktop app with only this code.  
Xojo 2019r3.1  
Win 10: English  
Region: Italy  
Regional format: Italian (Italy)

---

<div class="post-metadata">

**Author:** ![Jeannot\_Muller](https://forum.xojo.com/user_avatar/forum.xojo.com/jeannot_muller/32/13359_2.png) [@Jeannot\_Muller](https://forum.xojo.com/u/Jeannot_Muller)\
**Post date:** [October 14, 2020, 7:42am UTC](https://forum.xojo.com/t/datetime-fromstring/57888/13 "2020-10-14T07:42:57Z")

</div>

Very strange, this code is just fine and is running for me … :-(. You should open a ticket with Xojo on this.

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [October 14, 2020, 7:54am UTC](https://forum.xojo.com/t/datetime-fromstring/57888/14 "2020-10-14T07:54:23Z")

</div>

If you make the string a variable or a constant does ot work then?

---

<div class="post-metadata">

**Author:** ![Ulrich\_Bogun](https://forum.xojo.com/user_avatar/forum.xojo.com/ulrich_bogun/32/1864_2.png) [@Ulrich\_Bogun](https://forum.xojo.com/u/Ulrich_Bogun)\
**Post date:** [October 14, 2020, 9:02am UTC](https://forum.xojo.com/t/datetime-fromstring/57888/15 "2020-10-14T09:02:32Z")

</div>

Might just be your font, but to me the separators in your string look suspiciously long. Are you sure you used hyphens and not dashes?

---

<div class="post-metadata">

**Author:** ![Jeannot\_Muller](https://forum.xojo.com/user_avatar/forum.xojo.com/jeannot_muller/32/13359_2.png) [@Jeannot\_Muller](https://forum.xojo.com/u/Jeannot_Muller)\
**Post date:** [October 14, 2020, 9:45am UTC](https://forum.xojo.com/t/datetime-fromstring/57888/16 "2020-10-14T09:45:18Z")

</div>

That was my suspicion as well, but then he would likely get an error during compilation and not only at runtime, right? Very, very strange … @Giacomo_Bernardi what happens if you are writing the “buggy” line 4 exactly than line 2?

`Dim dNew as DateTime = ...`

But I’m sure you tested this already. Do we have anyone here running Xojo on an Italian Windows 10, who could help? These non-English system issues are often a pain in the neck.

---

<div class="post-metadata">

**Author:** ![Anthony\_G\_Cyphers](https://forum.xojo.com/user_avatar/forum.xojo.com/anthony_g_cyphers/32/16862_2.png) [@Anthony\_G\_Cyphers](https://forum.xojo.com/u/Anthony_G_Cyphers)\
**Post date:** [October 14, 2020, 9:50am UTC](https://forum.xojo.com/t/datetime-fromstring/57888/17 "2020-10-14T09:50:01Z")

</div>

> [@Giacomo\_Bernardi](#):
>
> Dim d As DateTime = DateTime.FromString(“1977-05-23”)

Just adding data. Also cannot replicate this issue here.

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [October 14, 2020, 10:05am UTC](https://forum.xojo.com/t/datetime-fromstring/57888/18 "2020-10-14T10:05:37Z")

</div>

> [@Jeannot\_Muller](#):
>
> That was my suspicion as well, but then he would likely get an error during compilation and not only at runtime, right?

No, because he’s passing a string into a method. The compiler would have no business parsing that at compile time.

---

<div class="post-metadata">

**Author:** ![Jeannot\_Muller](https://forum.xojo.com/user_avatar/forum.xojo.com/jeannot_muller/32/13359_2.png) [@Jeannot\_Muller](https://forum.xojo.com/u/Jeannot_Muller)\
**Post date:** [October 14, 2020, 10:18am UTC](https://forum.xojo.com/t/datetime-fromstring/57888/19 "2020-10-14T10:18:07Z")

</div>

I messed up “separators” and “quotes” … one way or the other, we’ll either all have a good laugh once we found the solution, or it is a weird serious bug.

---

<div class="post-metadata">

**Author:** ![Giacomo\_Bernardi](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Giacomo\_Bernardi](https://forum.xojo.com/u/Giacomo_Bernardi)\
**Post date:** [October 15, 2020, 11:20am UTC](https://forum.xojo.com/t/datetime-fromstring/57888/20 "2020-10-15T11:20:55Z")

</div>

I had used a string to simplify.  
but using a variable the result is the same

 ![image](https://forum.xojo.com/uploads/default/original/2X/f/f665b0f769d77859ddccc77c5654600682ac9d62.png)

 ![image](https://forum.xojo.com/uploads/default/original/2X/2/28f4af016f43a4e301436495938a4b05e97743f1.png)

[Next page](https://forum.xojo.com/t/datetime-fromstring/57888.md?page=2)
