How to convert date string in classic asp

Now I'm a little slowed down ...

I have a date string in the European format dd.mm.yyyy and need to convert it to mm.dd.yyyy using classic ASP. Quick ideas?

+4
source share
5 answers

If it is always in this format, you can use split

d = split(".","dd.mm.yyyy") s = d(1) & "." & d(0) & "." & d(2) 

it would also give dates e.g. 1.2.99

+4
source
 Dim arrParts() As String Dim theDate As Date arrParts = Split(strOldFormat, ".") theDate = DateTime.DateSerial(parts(2), parts(1), parts(0)) strNewFormat = Format(theDate, "mm.dd.yyyy") 
+4
source

OK, I just found the solution myself:

 payment_date = MID(payment_date,4,3) & LEFT(payment_date,3) & MID(payment_date,7) 
+2
source

This is the way to do this with the built-in health check for dates:

 Dim OldString, NewString OldString = "31.12.2008" Dim myRegExp Set myRegExp = New RegExp myRegExp.Global = True myRegExp.Pattern = "(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]((19|20)[0-9]{2})" If myRegExp.Test Then NewString = myRegExp.Replace(OldString, "$2.$1.$3") Else ' A date of for instance 32 December would end up here NewString = "Invalid date" End If 
+2
source

I have my own dates manipulation functions that I use in all my applications, but it was originally based on this example:

http://www.adopenstatic.com/resources/code/formatdate.asp

0
source

Source: https://habr.com/ru/post/1276859/


All Articles