Solved

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

Posted on 2011-03-23
6
326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 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