468,556 Members | 2,009 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Share your developer knowledge by writing an article on Bytes.

Format a database date

sashi
1,754 Expert 1GB
Format database date.

This snippet of code will allow you to take in a date parameter. It will check the date parameter to see if there is a valid time portion or not. It will then format the date in such a way as to be functional regardless of where or how it's used.

Expand|Select|Wrap|Line Numbers
  1. Public Function FormatDate(ByVal vdtDate As Date) As String
  2. Dim dtNullDate As Date
  3. FormatDate = "NULL"
  4.  
  5.   If vdtDate = dtNullDate Then Exit Function
  6.   If DatePart("h", vdtDate) = 0 And DatePart("n", vdtDate) = 0 And     DatePart("s", vdtDate) = 0 Then
  7.     FormatDate = "{d '" & Format$(vdtDate, "yyyy-mm-dd") & "'}"
  8.   Else
  9.     FormatDate = "{ts '" & Format$(vdtDate, "yyyy-mm-dd hh:nn:ss") & "'}"
  10.   End If
  11. End Function
  12.  
Dec 4 '06 #1
0 5482

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

15 posts views Thread by Simon Brooke | last post: by
5 posts views Thread by Macca | last post: by
1 post views Thread by Rotsj | last post: by
9 posts views Thread by insomniux | last post: by
2 posts views Thread by Hennie | last post: by
9 posts views Thread by Martin | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.