AmPm$
Takes one parameter, Source
Description:
This function converts 24-hour time formats to standardized 12-hour AM/PM format and normalizes existing AM/PM time inputs. It handles various input formats, including standalone times, date+time combinations, and malformed AM/PM designations. However, it does not validate the date and time values.
Format Rules:
Hour Digit Formatting
- Single digits: Used for standalone times and space-separated dates (user-friendly display)
- Double digits: Used for T-separated ISO formats (data/API consistency)
- 12-hour logic: 00:xx becomes 12:xx AM, 12:xx stays 12:xx PM, 13-23:xx becomes 1-11:xx PM
AM/PM Standardization
- All AM/PM designations converted to uppercase with single space: " AM" or " PM"
- Handles mixed case: "am", "PM", "Am", "pM", etc.
- Supports single letters: "A", "p", etc.
- Cleans up extra characters: "ammm" → " AM"
Date Preservation
- Space separator: "YYYY-MM-DD HH:MM:SS" format preserved with space and results in single digit hour
- T separator: "YYYY-MM-DDTHH:MM:SS" ISO format preserved with T and results in two digit hour
- Date portion passes through unchanged
Examples:
24-Hour Time Conversion
Html ("AmPm$ ""00:00:00"": " & (AmPm$ "00:00:00")) ' AmPm$ "00:00:00": 12:00:00 AM
Html ("AmPm$ ""01:00:00"": " & (AmPm$ "01:00:00")) ' AmPm$ "01:00:00": 1:00:00 AM
Html ("AmPm$ ""12:00:00"": " & (AmPm$ "12:00:00")) ' AmPm$ "12:00:00": 12:00:00 PM
Html ("AmPm$ ""13:00:00"": " & (AmPm$ "13:00:00")) ' AmPm$ "13:00:00": 1:00:00 PM
Html ("AmPm$ ""23:59:59"": " & (AmPm$ "23:59:59")) ' AmPm$ "23:59:59": 11:59:59 PM
Html ("AmPm$ ""9:15"": " & (AmPm$ "9:15")) ' AmPm$ "9:15": 9:15 AM
AM/PM Format Normalization
Html ("AmPm$ ""10:30 AM"": " & (AmPm$ "10:30 AM")) ' AmPm$ "10:30 AM": 10:30 AM
Html ("AmPm$ ""10:30AM"": " & (AmPm$ "10:30AM")) ' AmPm$ "10:30AM": 10:30 AM
Html ("AmPm$ ""10:30pm"": " & (AmPm$ "10:30pm")) ' AmPm$ "10:30pm": 10:30 PM
Html ("AmPm$ ""10:30A"": " & (AmPm$ "10:30A")) ' AmPm$ "10:30A": 10:30 AM
Html ("AmPm$ ""10:30P"": " & (AmPm$ "10:30P")) ' AmPm$ "10:30P": 10:30 PM
Date + Time Combinations (Single-Digit Hours)
Html ("AmPm$ ""2025-01-15 00:00:00"": " & (AmPm$ "2025-01-15 00:00:00")) ' AmPm$ "2025-01-15 00:00:00": 2025-01-15 12:00:00 AM
Html ("AmPm$ ""2025-01-15 09:30:00"": " & (AmPm$ "2025-01-15 09:30:00")) ' AmPm$ "2025-01-15 09:30:00": 2025-01-15 9:30:00 AM
Html ("AmPm$ ""2025-01-15 13:30:00"": " & (AmPm$ "2025-01-15 13:30:00")) ' AmPm$ "2025-01-15 13:30:00": 2025-01-15 1:30:00 PM
Html ("AmPm$ ""2025-01-15 23:59:59"": " & (AmPm$ "2025-01-15 23:59:59")) ' AmPm$ "2025-01-15 23:59:59": 2025-01-15 11:59:59 PM
Date + Time Combinations (Double-Digit Hours for ISO Format)
Html ("AmPm$ ""2025-01-15T00:00:00"": " & (AmPm$ "2025-01-15T00:00:00")) ' AmPm$ "2025-01-15T00:00:00": 2025-01-15T12:00:00 AM
Html ("AmPm$ ""2025-01-15T09:30:00"": " & (AmPm$ "2025-01-15T09:30:00")) ' AmPm$ "2025-01-15T09:30:00": 2025-01-15T09:30:00 AM
Html ("AmPm$ ""2025-01-15T13:30:00"": " & (AmPm$ "2025-01-15T13:30:00")) ' AmPm$ "2025-01-15T13:30:00": 2025-01-15T01:30:00 PM
Html ("AmPm$ ""2025-01-15T23:59:59"": " & (AmPm$ "2025-01-15T23:59:59")) ' AmPm$ "2025-01-15T23:59:59": 2025-01-15T11:59:59 PM
AM/PM with Dates
Html ("AmPm$ ""2025-01-15 10:30 AM"": " & (AmPm$ "2025-01-15 10:30 AM")) ' AmPm$ "2025-01-15 10:30 AM": 2025-01-15 10:30 AM
Html ("AmPm$ ""2025-01-15 10:30pm"": " & (AmPm$ "2025-01-15 10:30pm")) ' AmPm$ "2025-01-15 10:30pm": 2025-01-15 10:30 PM
Html ("AmPm$ ""2025-01-15T10:30 PM"": " & (AmPm$ "2025-01-15T10:30 PM")) ' AmPm$ "2025-01-15T10:30 PM": 2025-01-15T10:30 PM
Html ("AmPm$ ""2025-01-15T10:30A"": " & (AmPm$ "2025-01-15T10:30A")) ' AmPm$ "2025-01-15T10:30A": 2025-01-15T10:30 AM