471,324 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 471,324 developers and data experts.

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 5620

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 rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.