Connecting Tech Pros Worldwide Help | Site Map

Format a database date

  #1  
Old December 4th, 2006, 09:53 AM
sashi's Avatar
Expert
 
Join Date: Jun 2006
Location: Seremban, Malaysia
Posts: 1,630
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.  

Last edited by RedSon; November 21st, 2007 at 07:05 PM.



Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date format Database to Word changes AA Arens answers 3 October 18th, 2006 02:45 PM
Save blank fields in database (date and integer) - Error Øyvind Isaksen answers 5 February 4th, 2006 05:25 PM
Form entry to Time part of database Date entry? Noozer answers 2 August 1st, 2005 11:25 PM
Time/Date format and changing time to GMT Shaiboy_UK answers 1 July 19th, 2005 09:05 AM