Purpose Display a date in a verbose format, including the day of the week and name of month The previous tip shows a solution without calling a VB .NET function |
Solution Set V[mydate] "06.01.2018" // sample date, could be any date format / / Call VB function to build up the long date format// We pass the language id, system variable V[_language2], e.g. "en" CallVB verboseDate = utilities.mydate.build_verbose_date _"&V[mydate]" "&V[_language2]" Message "&V[verboseDate]" |
VB Imports System.Globalization Public Class mydate Function build_verbose_date(mydate As String, language As String) _ As String ' parse given date string Dim d As Date = parseDate(mydate) ' culture info Dim ci As CultureInfo = CultureInfo.CreateSpecificCulture(language) ' format date Return d.ToString("D", ci) End Function ' parse given date string, trying various formats Function parseDate(mydate As String) As Date Dim d As Date Dim formats() As String = {"yyyyMMdd", _ "yyyy-MM-dd", "yyyy-MM-d", "yyyy-M-dd", "yyyy-M-d", _ "dd.MM.yyyy", "d.MM.yyyy", "dd.M.yyyy", "d.M.yyyy", _ "MM/dd/yyyy", "M/d/yyyy", "MM/d/yyyy", "M/dd/yyyy"} Try d = Date.ParseExact(mydate, formats, _ DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AllowWhiteSpaces) Catch ex As Exception Return Date.MinValue End Try Return d End Function End Class |
Components |