0

If I accept a date from a user using ask and then wish to use it as a Date by using to-date, I get an error.

>> to-date "31-Dec-2019"
*** Script Error: cannot MAKE/TO date! from: "31-Dec-2019"
*** Where: to
*** Stack: to-date

What is the correct way of converting a string to date ?

rahul
  • 598
  • 1
  • 9
  • 20

1 Answers1

2

You have to use load

>> load "31-Dec-2019"
== 31-Dec-2019

a few examples for to-date!

>> to-date 1547196008
== 11-Jan-2019/8:40:08
>> to-date [200 1 1]
== 1-Jan-0200
sqlab
  • 6,412
  • 1
  • 14
  • 29
  • 1
    In Rebol2 the 'to-date function works as expected by the user. Why does Red have a 'to-date function when it does not do what it promises to do? Seems to me it should be either fixed or removed or the help string should point out it is deprecated and 'load should be used instead. – iArnold Jan 11 '19 at 08:17
  • 2
    Red is still **alpha** – sqlab Jan 11 '19 at 08:44
  • Thanks, sqlab. The issue is that people new to red are referred to the rebol docs, so I am using some rebol articles and books to learn red. I am unable to find a proper tutorial for red itself. I keep hitting things (in rebol books) that don't work in red and am trying to find the corresponding function. Thanks again. – rahul Jan 11 '19 at 09:08
  • 3
    @rahul official reference documentation has a [detailed section](https://doc.red-lang.org/en/datatypes/date.html) for `date!` datatype and its conversion. We also have an extensive list of [learing resources](https://github.com/red/red/wiki/[LINKS]-Learning-resources) and active [community hub](https://gitter.im/red/help), where you can ask for help. – 9214 Jan 11 '19 at 20:03
  • For the record, most of `to ` converters are not yet implemented. It works for `to-integer` and `to-float`. `load` provides a good alternative in the meantime. – DocKimbel Jan 12 '19 at 04:17