1.

Solve : VB 6 .....ASP?

Answer»

Can some please tell me what this function does?

Function SwopIt(tmpDatum)
Dim dd
Dim mm
Dim yyyy
Dim tmpDate
Dim pos1, pos2
tmpDate = FormatDateTime(tmpDatum,2)
pos1 = InStr(1, tmpDate, "/")
pos2 = InStr(pos1 + 1, tmpDate, "/")
mm = Mid(tmpDate, 1, pos1 - 1)
dd = Mid(tmpDate, pos1 + 1, pos2 - pos1 - 1)
yyyy = Right(tmpDate, 4)
SwopIt = dd & "/" & mm & "/" & yyyy
End Function

Private Function MakeDate(aDate)
Dim dpart,mpart,ypart,tmpDate

dpart = DatePart("d", aDate)
If Len(dpart) = 1 Then dpart = "0" & dpart
mpart = DatePart("m", aDate)
Select CASE mpart
Case 1
mpart = "Jan"
Case 2
mpart = "Feb"
Case 3
mpart = "Mar"
Case 4
mpart = "Apr"
Case 5
mpart = "May"
Case 6
mpart = "Jun"
Case 7
mpart = "Jul"
Case 8
mpart = "Aug"
Case 9
mpart = "Sep"
Case 10
mpart = "OCT"
Case 11
mpart = "Nov"
Case 12
mpart = "DEC"
End Select

ypart = DatePart("yyyy", aDate)
MakeDate = dpart & " " & mpart & " " & ypart
End FunctionThere are actually two functions. SwopIt converted my local date (mm/dd/yyyy) to dd/mm/yyyy. MakeDate converted my local date (mm/dd/yyyy) to dd mmm yyyy.

Note: if passing data to the functions, be sure the data is dimmed as date. If you're hardcoding literals to the functions, be sure the enclose the data with # symbols. The results may surprise you if you fail to do so.



Thanks so much.
My suprise is, if i save the date as 05 Feb 2009, what i get on my display page is 02 May 2009.
Its really confusing me. I took over this code from someone and i have to make sure that our clients get the right information as the one that they have saved in the db.Quote

My suprise is, if i save the date as 05 Feb 2009, what i get on my display page is 02 May 2009.

Until I passed a #date# field, I kept getting a 1899 year as xx/xx/xxxx was being computed as a series of arithmetic divisions.

Try modifying the function headers. This will force an error if the data is mistyped.

Code: [Select]Function SwopIt(tmpDatum as Date) as Date

Private Function MakeDate(aDate as Date) as Date

Make sure the database field is ALSO defined as a date.

Thanks so much, i got it right. I removed the function call to SwopIt which was interchanging the date with the month.

Thanks


Discussion

No Comment Found