Work with If-Modified-Since and Last-Modified

'Converts date (19991022 11:08:38)   'to http form (Fri, 22 Oct 1999 12:08:38 GMT)   Function DateToHTTPDate(ByVal OleDATE As Date) As String
    On Error Resume Next
    OleDATE = OleDATE.ToUniversalTime
    Return engWeekDayName(OleDATE) & _
     ", " & Right("0" & Day(OleDATE), 2) & " " & engMonthName(OleDATE) & _
     " " & Year(OleDATE) & " " & Right("0" & Hour(OleDATE), 2) & _
     ":" & Right("0" & Minute(OleDATE), 2) & ":" & Right("0" & Second(OleDATE), 2) & " GMT"
  End Function

  Function engWeekDayName(ByVal dt As Date) As String
    Dim Out As String
    Select Case WeekDay(dt, 1)
      Case 1 : Out = "Sun"
      Case 2 : Out = "Mon"
      Case 3 : Out = "Tue"
      Case 4 : Out = "Wed"
      Case 5 : Out = "Thu"
      Case 6 : Out = "Fri"
      Case 7 : Out = "Sat"
    End Select
    Return Out
  End Function

  Function engMonthName(ByVal dt As Date) As String
    Dim Out As String
    Select Case Month(dt)
      Case 1 : Out = "Jan"
      Case 2 : Out = "Feb"
      Case 3 : Out = "Mar"
      Case 4 : Out = "Apr"
      Case 5 : Out = "May"
      Case 6 : Out = "Jun"
      Case 7 : Out = "Jul"
      Case 8 : Out = "Aug"
      Case 9 : Out = "Sep"
      Case 10 : Out = "Oct"
      Case 11 : Out = "Nov"
      Case 12 : Out = "Dec"
    End Select
    Return Out
  End Function

  Public Function DateFromHTTP(ByVal HTTPDate As String) As Date
    Dim Swd As String, d As String, Sm As String, y As String, h As String
    Dim m As String, s As String, g As String, Out As Date
    HTTPDate = LCase$(HTTPDate)

    If Mid$(HTTPDate, 27, 3) = "gmt" Then
      Swd = Left$(HTTPDate, 3)
      d = Mid$(HTTPDate, 6, 2)
      Sm = Mid$(HTTPDate, 9, 3)
      y = Mid$(HTTPDate, 13, 4)
      h = Mid$(HTTPDate, 18, 2)
      m = Mid$(HTTPDate, 21, 2)
      s = Mid$(HTTPDate, 24, 2)
      Out = New Date(y, mFromSm(Sm), d, h, m, s)
      Out = Out.ToLocalTime
    End If

    Return Out
  End Function
This entry was posted in Code Snippets. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s