Solved

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

Posted on 2011-03-23
6
324 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Title # Comments Views Activity
vb.net class 3 21
SQL Server Connection String through a VPN 8 55
Code enhancement 4 21
I need help adding validation to my MVC.Net view 6 4
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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