I can't evaluate a DateTime value

isabtogumonisabtogumon Member Posts: 28
Hi,

I'm trying to evaluate a value, however I am getting the following error:

The value "2021-02-16T09:26:36.953" can't be evaluated into type DateTime.

With what method can I solve the problem?

Best Answer

  • isabtogumonisabtogumon Member Posts: 28
    Accepted Answer
    I solved the problem, I did it this way
    
    txtDate := '2021-02-16T09:26:36.953';
    txtNewDate := CopyStr(txtDate, 1, 4)
    + '-' + CopyStr(txtDate, 6, 2)
    + '-' + CopyStr(txtDate, 9, 2)
    + ' ' + CopyStr(txtDate, 12, 2)
    + ':' + CopyStr(txtDate, 15, 2)
    + ':' + CopyStr(txtDate, 18, 2);
    Evaluate(formatDate, txtNewDate);
    Data.DateMov := formatDate;
    

    Thank you for your answers

Answers

  • CodeViperCodeViper CanadaMember Posts: 25
    DateTime := CREATEDATETIME(Date, Time)
    or
    NewDateTime := ROUNDDATETIME(Datetime [, Precision][, Direction])
    or
    *this one below is to just get the date from the value you indicated
    Date := DT2DATE(Datetime)


    not sure what you are trying to do or evaluate it to...
  • lyngelynge Jutland, DenmarkMember Posts: 84
    Evaluate(MyDateTime,'2021-02-16T09:26:36.953',9); // Note the ,9 parameter
  • isabtogumonisabtogumon Member Posts: 28
    Hi @CodeViper, I want to convert text to date and time, date value that I get in text format through a variable, which in turn I get from an element of an XML.
    Evaluate(varDateTime, (xmlNod.AsXmlElement().InnerText),9);
    Data.DateTime := varDateTime;
    

    I tried the above but it is not accurate since when converting this date "2021-02-16T09: 26: 36.953" the method returns this "02/16/2021 03:26 AM". Is there a way to segment the text to get the precise time?
  • isabtogumonisabtogumon Member Posts: 28
    Hi @lynge,

    I tried your suggestion, however the method does not return the precise time. I got this value: "02/16/2021 03:26 am"

    Is there any other method to convert from this value "2021-02-16T09: 26: 36.953" to this value "02/16/2021 09:26:36 a. m.", since the first value is text format?

  • isabtogumonisabtogumon Member Posts: 28
    Accepted Answer
    I solved the problem, I did it this way
    
    txtDate := '2021-02-16T09:26:36.953';
    txtNewDate := CopyStr(txtDate, 1, 4)
    + '-' + CopyStr(txtDate, 6, 2)
    + '-' + CopyStr(txtDate, 9, 2)
    + ' ' + CopyStr(txtDate, 12, 2)
    + ':' + CopyStr(txtDate, 15, 2)
    + ':' + CopyStr(txtDate, 18, 2);
    Evaluate(formatDate, txtNewDate);
    Data.DateMov := formatDate;
    

    Thank you for your answers
Sign In or Register to comment.