Search notes:

VBA: Convert a UTC text to a date

A combination of dateSerial(), timeSerial() and mid() allows to create a date from a string.
The following example tries to demonstrate how a string that is formatted according to UTC (without timezone) might be converted to a date.
The following function UTCStringToDate() tries to demonstrate how these two functions might be combined with mid() to create a date from a UTC string.
option explicit

sub main() ' {

    dim dt_

    dt_ = UTCStringToDate("2018-02-27T15:16:17Z")

    debug.print(format$(dt_, "dd.mm.yyyy - hh:nn:ss"))

end sub ' }

function UTCStringToDate(utc as string) as date ' {

    UTCStringToDate = dateSerial(           _
                         mid(utc, 1, 4),    _
                         mid(utc, 6, 2),    _
                         mid(utc, 9, 2)) +  _
                      timeSerial( _
                         mid(utc,12, 2),    _
                         mid(utc,15, 2),    _
                         mid(utc,18, 2))


end function ' }
Github repository about-VBA, path: /language/datatypes/date/utc-to-date.bas

See also

Date and time related functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1745775229, '3.15.226.5', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/VBA/language/datatypes/date/convert-UTC-text-to-date(71): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78