Turning a string into date/time and back

Turning a string into date/time and back

 Thanks to Gaev and Zoho developer friends for helping with my scheduling app.

Here is a function for anyone who is trying to do something similar--it takes times formatted as strings (such as 10:00 AM), and convert to date/time for calculation, such as adding 2 hours.

Convert string to date/time:

date TextTimetoRealTime(string texttime, date newdate)
{
    //This function takes a time string formatted with AM/PM (ex 2:30 PM) and converts it to a real time/date.  Arguments are the source of the time string, and some date field or variable.
    //RETURNS DATE ONLY IF NO AM/PM ON STRING. 
    //Parse time string
    //Minutes
    varMin = (input.texttime.getSuffix(":")).getPrefix(" ");
    //AM/PM
    varAMPM = (input.texttime.getSuffix(":")).getSuffix(" ");
    //Hour (adds 12 hours if PM)
    varHour = input.texttime.getPrefix(":");
    if (varAMPM  ==  "PM")
    {
        varMilitaryHour = (varHour.toLong()  +  12);
    }
    else
    {
        varMilitaryHour = varHour.toLong();
    }
    //Parse real date and convert to strings
    //Month
    varMonth = (input.newdate.getMonth()).toString();
    //Day
    varDay = (input.newdate.getDay()).toString();
    //Year
    varYear = (input.newdate.getYear()).toString();
    //Puts date and time strings in correct format for converstion to date/time
    varStringDateandMilitaryTime = varMonth + "/" + varDay + "/" + varYear + " " + varMilitaryHour + ":" + varMin + ":00";
    varRealDateTime = varStringDateandMilitaryTime.toTime();
    return varRealDateTime;
    //<comment>
}