locked
Regular Expression help RRS feed

  • Question

  • User-1188570427 posted

    CAST(N'2017-09-24 21:04:54.880' AS DateTime) where the seconds are different. 

    I need to take this line of code and update it to GetUTCDate() with the find/replace functionality using regular expressions.

    How could I do that in Visual Studio?

    Tuesday, August 28, 2018 9:46 PM

All replies

  • User2103319870 posted

    Instead of using Regex, you can use Replace function like below

    string queryValue = "CAST(N'2017-09-24 21:04:54.880' AS DateTime)";
    queryValue = queryValue.Replace("CAST(N'2017-09-24 21:04:54.880' AS DateTime)","GetUTCDate()");

    Tuesday, August 28, 2018 11:28 PM
  • User-1188570427 posted

    Instead of using Regex, you can use Replace function like below

    string queryValue = "CAST(N'2017-09-24 21:04:54.880' AS DateTime)";
    queryValue = queryValue.Replace("CAST(N'2017-09-24 21:04:54.880' AS DateTime)","GetUTCDate()");

    Updated the post: but the seconds change :-( Didn't update it properly. 

    Tuesday, August 28, 2018 11:50 PM
  • User1724605321 posted

    Hi tvb2727 ,

    What do you mean by "Didn't update it properly" . Any error occurs or the date is not correct after saving to DB ? And also describe your requirement clearly. 

    Best Regards,

    Nan Yu

    Wednesday, August 29, 2018 6:18 AM
  • User-1188570427 posted

    Hi tvb2727 ,

    What do you mean by "Didn't update it properly" . Any error occurs or the date is not correct after saving to DB ? And also describe your requirement clearly. 

    Best Regards,

    Nan Yu

    I didn't update initial post properly. Where the seconds change and can be different.

    Wednesday, August 29, 2018 10:29 AM