Code Snippets

  

Visual Basic Source Code


Welcome to Dream.In.Code
Become a VB Expert!

Join 149,631 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,112 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,528

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.




Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month