+ Reply to Thread
Results 1 to 2 of 2

Thread: Convert String to Time

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    35

    Convert String to Time

    Hi , i have that SQL Query that return date in string and i want to create a method on my application to calculate the difference between the two dates , here is the Sql query :
    Code:
    LEFT(CONVERT(VARCHAR(8), te.StartTime, 8), 5) AS [Start Time], 
    LEFT(CONVERT(VARCHAR(8), te.FinishTime, 8), 5) AS [Finish Time]
    In my application i tried that code , but it didn`t work :
    Code:
    DateTime startTime = (DateTime)varValue;
    DateTime finishTime = (DateTime)varFinish;
    But i get the error message 'invalid cast' and i don`t know what is that ....!

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    13
    Can you try the below code ?
    Code:
    DateTime now = DateTime.Now;
    DateTime startTime = DateTime.Parse(varValue + " " + now.ToShortDateString());
    DateTime finishTime = DateTime.Parse(varFinish + " " + now.ToShortDateString());

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts