Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2008
    Leyland in NW England, UK

    Question Unanswered: Convert string to Time Value

    I want to be able to work out length of time taken by taking one time away from another e.g. Deploy_Time "15:45" minus Systime "15:30" = "00.15".

    However, unfortunately both fields are varchar string fields so cannot take one from the other.

    Have tried using:
    CTime({Deploy_Time}) - CTime({Systime})

    but comes up with "Bad Time Format String" Error message.

    Can anyone help me convert the values in these fields - please?

  2. #2
    Join Date
    Oct 2007
    If time is not working for you, try converting to a datetime.

    Take a date string (any will do), lets say "2008-01-01 " and append your times...

    "2008-01-01 " + "15:45" and "2008-01-01 " + "15:30".

    Also, a minus sign will not always work for date and time values. You will want to use a DateDiff function. If there is a TimeDiff function, you may not even need to prepend the date part. However, with a function like DateDiff, you will need to determine what type of difference you want (minutes, seconds, etc).

    When working with strings that need to be recast, sometimes it is hard to tell if you are casting them wrong or if your new formula is wrong. Let's say i have a {SysTime} field from my data that is a string... I find it easier to create a formula {@SysTime} that simply converts the string to a time value.

    Then, i don't have to reconvert my string data everywhere that i use it; i can just use the {@SysTime} formula instead. Crystal Reports will also tell you if your problem is in your CTime or if it is in your subtraction formula.

Posting Permissions

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