?
Solved

How to stop Date/Time field from showing TIME

Posted on 2004-11-19
7
Medium Priority
?
246 Views
Last Modified: 2010-04-23
I have an access database with a Date/Time field.
When I send the Date/Time field to my lblBirthDate it shows the date thats in the field....but then it shows "12:00:00 AM".

So I want to strip off the 12:00:00 AM part so I used the code below...the problem is that when the form loads the lblBirthDate is empty and my Constructor code is cant run with no date, so the form won't load. I tried "If lblBirthDate = "" Then exit sub Else run code" but then the form loads but my constructor code never runs.

How can I load a record after Form_Load, and fill in lblBirthDate,  but not have the time.
 
 -----------CODE----------------CODE----------------CODE-------------
'Add this code in the constructor of the form
public sub new
  AddHandler label1.DataBindings("Text").Format, AddressOf DateToString
end sub

 ' Handles the Format event for the date
Protected Sub DateToString(ByVal sender As Object, ByVal e As ConvertEventArgs)
        ' You could use either of the following to convert to the proper date
        ' format:
        'e.Value = CType(e.Value, DateTime).ToString("mm/dd/yyyy")
        e.Value = CType(e.Value, DateTime).ToShortDateString
    End Sub
 
0
Comment
Question by:Matrix1000
7 Comments
 
LVL 28

Assisted Solution

by:iboutchkine
iboutchkine earned 400 total points
ID: 12628406
dim s as s tring
s = Format(e.Value, "MM/dd/yyyy").ToString
e.Value = s
0
 
LVL 1

Author Comment

by:Matrix1000
ID: 12628645
Where would I add that?  
0
 
LVL 1

Author Comment

by:Matrix1000
ID: 12628674
When I add it at the bottom of my DatabaseSearch() sub it underlines " e.Value" saying "Value not a member of System.EventArgs"
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 18

Assisted Solution

by:DotNetLover_Baan
DotNetLover_Baan earned 800 total points
ID: 12629303
Hi there,
replace this line >> e.Value = CType(e.Value, DateTime).ToShortDateString << with
e.Value = CType(e.Value, Date).ToShortDateString
-Baan
0
 
LVL 1

Author Comment

by:Matrix1000
ID: 12629451
-Baan

Thanks! but the form still wont load at first....I get an errror highlighting
"AddHandler label1.DataBindings("Text").Format, AddressOf DateToString"

Error: Additional information: Object reference not set to an instance of an object.

---------CONSTRUCTOR CODE AT THE TOP OF MY CODE-------------------

 Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

        'THIS AddHandler FORMATS MY DATE BOXES TO STRIP OFF THE TIME '12:00:00AM
        AddHandler lblBirthDate.DataBindings("Text").Format, AddressOf DateToString

    End Sub
----------------------------------------------------------
Is it because there is no date in the lblBirthDate yet while the form loads?
0
 
LVL 7

Expert Comment

by:davidrichardson
ID: 12630953
i had big probles with a date/time field, in the end i converted it text which solved all my problems
0
 
LVL 2

Accepted Solution

by:
AmanBrar earned 800 total points
ID: 12653798
Hi, try using this -
Dim mytime = Format(Now.Date, "mm/dd/yyyy")
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question