Solved

Accessing Date And Time Separately From A Date/Time Field In An Access Database

Posted on 2011-03-23
6
298 Views
Last Modified: 2012-05-11
Hi

I am using Visual Basic.Net (Visual Studio 2008) and an Access 2007 Database. In the Access Database I a have Field called LvDate and its Storage format is Date/Time. At Any point in time, I put the value of Now in there. For example the field content is 23/03/2011 10:23:45. What is the easiiest way of addressing and extracting each one of these separately - I wish to show the Date and Time components under diifferent column headings in a report or enquiry say.

Many thanks
0
Comment
Question by:Nolanc
  • 2
  • 2
  • 2
6 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35197046
You would still pull the data from the database into a single DateTime variable in code. You then simply use formatting features of the grid/report to display either the time or date part of the value.

For example, if you were displaying in a grid you might use:
<span><%# Eval("YourField", "dd/MM/yyyy") %></span>

Open in new window

0
 

Author Comment

by:Nolanc
ID: 35197218
Hi carl tawn

I am not sure what language you are using as an example but let's say I am reading from the affected table and I wish to do the following:

Dim dDate as DateTime   (as you are suggesting)

ddate = dsLvH.Tables("LvHis").Rows(I).Item("LvDate")    which I think is what you are suggesting

Now I wish To display the Time component for each record as follows:

MsgBox (dDate.TimeOfDay)

I get a Run-Time error saying it is unable to convert the data to type String - It looks like I have to do a conversion of some description for MsgBox.

Am I on the right track

Thanks
0
 
LVL 5

Expert Comment

by:karstieman
ID: 35197228
Dim i As Integer
Dim aryTextFile() As String

LineOfText = "UserName1, Password1, UserName2, Password2"

aryTextFile = dDate.tostring.Split(" ")

For i = 0 To UBound(aryTextFile)
MsgBox(aryTextFile(i))
Next i
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 52

Accepted Solution

by:
Carl Tawn earned 100 total points
ID: 35197235
If you want to show it in a message box like that you would pass a format to the ToString() method to control the format:
MsgBox(dDate.ToString("HH:mm"))        '// display the time only

Open in new window

0
 
LVL 5

Expert Comment

by:karstieman
ID: 35197248
oops. one line should not be in my code ;-)
Dim i As Integer
Dim aryTextFile() As String

aryTextFile = dDate.tostring.Split(" ")

For i = 0 To UBound(aryTextFile)
MsgBox(aryTextFile(i))
Next i

Open in new window

0
 

Author Closing Comment

by:Nolanc
ID: 35197333
Hi carl tawn

Thanks. It works beautifully.

Nolanc
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now