Accessing current system date and time

Help
Byron S
2010-12-07
2012-11-23
  • Byron S
    Byron S
    2010-12-07

    Does anyone know of a way to retrieve the current date and time from the operating system?  I'm using CLIPS 6.3 on a Windows platform.  

     
  • Gary Riley
    Gary Riley
    2011-01-01

    Here's one way to retrieve the values as strings:

    CLIPS>
    (deffunction system-string (?arg)
       (bind ?arg (str-cat ?arg " > temp.txt"))
       (system ?arg)
       (open "temp.txt" temp "r")
       (bind ?rv (readline temp))
       (close temp)
       ?rv)
    CLIPS> (system-string "date /t")
    "Sat 01/01/2011 "
    CLIPS> (system-string "time /t")
    "05:34 PM"
    CLIPS>

     
  • Dani Morgado
    Dani Morgado
    2012-01-20

    Hi, i would like to know how to get only the year if it would be possible.

    Thanks a lot

     
  • Gary Riley
    Gary Riley
    2012-04-13

    Once you've got the string with the date in it, just use the string manipulation functions:

    CLIPS> (sub-string 11 14 "Sat 01/01/2011 ")
    "2011"
    CLIPS>