Code Snippets

  

Visual Basic Source Code


Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 131,103 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,146 people online right now. Registration is fast and FREE... Join Now!





Date (in words) to Oracle Date Format

Converts Strings in format "DD MONTH YYYY" to Oracle Date Format. For eg. StrToDate("16 November 2005") returns "16-NOV-2005"

Submitted By: born2c0de
Actions:
Rating:
Views: 10,078

Language: Visual Basic

Last Modified: October 5, 2005

Snippet


  1. ' Written by Sanchit Karve
  2. '     born2c0de
  3. '     born2c0de@hotmail.com
  4.  
  5. Public Function StrToDate(ByVal strng As String) As String
  6.     Dim d As Integer
  7.     Dim m As Byte
  8.     Dim Y As Integer
  9.     Dim i As Integer
  10.     Dim tmp As String, tmp1 As String
  11.     strng = Trim(strng)
  12.     d = Int(Val(strng))
  13.     Y = Val(Right(strng, 4))
  14.     strng = Mid(strng, 1, Len(strng) - 5)
  15.     For i = Len(strng) To 1 Step -1
  16.         If Asc(Mid(strng, i, 1)) >= 65 Then tmp = tmp + Mid(strng, i, 1) Else Exit For
  17.     Next i
  18.     tmp = StrReverse(tmp)
  19.     tmp = Left(tmp, 3)
  20.     tmp1 = Trim(tmp1)
  21.     tmp1 = IIf(d < 10, "0" + Trim(Str(d)), Trim(Str(d)))
  22.     tmp1 = Trim(tmp1) + "-" + UCase(tmp) + "-" + Trim(Str(Y))
  23.     StrToDate = tmp1
  24. End Function
  25.  
  26. '  EXAMPLE
  27. '
  28. ' Msgbox StrToDate("6 February 2005")
  29.  

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month