473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Why on earth VB.NET gives me this date, "12/30/1899", when it's supposed to give just a time value?

I am using Access Database in my program. The column in the table that I am
going to use has date/time value with Medium Time selected. (HH:mm). The
program is recording a clock in time to this field, which is the time when
the entry is made. If you check the database, it shows the correct time in
the correct format. But when you are calling it with a dataset and showing
with a datagrid, it doesn't show the time value but it always shows
12/30/1899. I searched for this error a lot, and found out that, that's the
minimum year used in Access, but why is it not bringing the time value which
I am calling for? Any help would be highly appreciated. I have been trying
to resolve this error for two days and two nights now and really bored of
it. (Kinda like it though)

Here is the code that inserts the clock in time to the database
-----------------------------------------------------------------------

Dim dayOfWeek As Date
Dim clockIn As Date

dayOfWeek = CDate(String.Format("{0:d}", Now()))
'************************************************* *
'THAT'S WHERE I DEFINE THE TIME VALUE TO BE INSERTED IN THE ACCESS DATABASE
clockIn = CDate(String.Format("{0:t}", Now()))
'************************************************* *

Dim conn As New OleDbConnection(connectionString)
Dim sql As String = "SELECT * FROM TimeLog WHERE employeeID = " _
& "'" & userName & "'"

Try
conn.Open()
Dim da As New OleDbDataAdapter(sql, conn)
Dim ds As New DataSet()

da.Fill(ds, "TimeLog")
Dim cmdBuilder As New OleDbCommandBuilder(da)
da.InsertCommand = cmdBuilder.GetInsertCommand
da.UpdateCommand = cmdBuilder.GetUpdateCommand
Dim dt As DataTable = ds.Tables(0)

With dt
Dim dr As DataRow = .NewRow
dr("employeeID") = userName
dr("dayOfWeek") = dayOfWeek
'***************************************
'THE DATA IS INSERTED HERE
dr("clockStart") = clockIn
'***************************************
.Rows.Add(dr)
End With

da.Update(ds, "TimeLog")
da.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
conn.Close()
Me.Close()
End Try

----------------------------------------------------------------------------
--------
Now in another form, when I call the database table, the time value(clockIn)
above is shown as #12/30/1899#
Here is the second form that calls the values in the database
----------------------------------------------------------------------------
--------

Dim conn As New OleDbConnection(connectionString)
Dim sql As String = "SELECT dayOfWeek As [Dates], TimeLog.employeeID AS
[UserName], " _
& "firstName, lastName, " _
& "clockStart AS [ClockIn], clockEnd As
[ClockOut], " _ ' THOSE TWO VALUES ARE BROUGHT TO THE DATAGRID WITH
12/30/1899 VALUES
& "payRate, DATEDIFF (dd, clockStart, clockEnd)
AS [Hours] " _
& "FROM Employee INNER JOIN TimeLog ON
Employee.employeeID = TimeLog.employeeID " _
& "WHERE TimeLog.employeeID = " & "'" & userName
& "' " _
& "AND dayOfWeek >= " & "#" & weekOneStartDay &
"# " _
& "ORDER BY dayOfWeek"
Try
conn.Open()
Dim da As New OleDbDataAdapter(sql, conn)
Dim ds As New DataSet()
da.Fill(ds, "EmployeeTimeLog")
da.Dispose()

If ds.Tables.Count = 0 Then
MessageBox.Show("Invalid username", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Else
dgrTimeLog.DataSource = ds.Tables(0)
End If

Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
conn.Close()
dgrTimeLog.Visible = True
End Try

Thanks in advance for your times and efforts to read those codes..
RENEY
Nov 20 '05 #1
3 11689
Hi Joe,

Thanks a lot...Now I understand why it is giving me this weird date. I
changed the program as it inserts a general date(G)and time now. But still,
when I run the query, it only gives me the year part of it. But I need just
the time portion. How could I cut the date part from the query? I am trying
to use the Datepart function, but I couldn't do it yet. If you have any
idea, I would be so glad,

Thanks,
Reney

"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Access date/time values are based on the integer and decimal parts of the
stored value.
So, 0.5 is date zero and it is 1/2 way through the day so it is Noon.

If you only pass a time value, then the date part is always 0.
That is why you get 12/30/1899.

--
Joe Fallon

Nov 20 '05 #2
Hi Jerry,
As far as I know, the minimum date used in Access is 1/1/1000

It may be the minimum Access can handle, but it does not equate
to 0 (zero), it would be a (very large) negative number. (See
Joe's reply)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :-)

Nov 20 '05 #3
Hi Reney,
How could I cut the date part from the query?

I might use the Format() function:

Format([clockStart], "hh:mm:ss") AS clockIn

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:-)

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sorisio, Chris | last post by:
Ladies and gentlemen, I've imported some data from a MySQL database into a Python dictionary. I'm attempting to tidy up the date fields, but I'm receiving a 'mx.DateTime.Error: cannot convert...
33
by: Steven Bethard | last post by:
I feel like this has probably been answered before, but I couldn't find something quite like it in the archives. Feel free to point me somewhere if you know where this has already been answered. ...
14
by: David B. Held | last post by:
I wanted to post this proposal on c.l.c++.m, but my news server apparently does not support that group any more. I propose a new class of exception safety known as the "smart guarantee". ...
5
by: kmunderwood | last post by:
I am trying to combine "if match=" and "when test" I am a newbie, and have made both work separately, but I can not seem to combine them. This is my xml("index.xml")page(I can not change this,...
1
by: jw56578 | last post by:
I execute a simple query with "for xml auto". One of the fields in my table is "char" type and has a blank value. when the query gets to this field the xml construction stops. such that it creates...
5
by: Larry R Harrison Jr | last post by:
I use the Lebans calendar control and love it; the only thing is that it commonly starts out at the year 1899 rather than the current year. Is there a way to specifically tell it to start at the...
7
by: dongdong | last post by:
using web browser can get page's content formally, but when use urllib2.open("http://tech.163.com/2004w11/12732/2004w11_1100059465339.html").read() the result is <html><head><META...
1
by: afr0ninja | last post by:
Hello all, and thank you in advance for your assistance. I'm pretty new to access and I'm trying to teach myself some VBA by using various bits of code I find here and there mixed with my own....
17
by: David C. Ullrich | last post by:
Having a hard time phrasing this in the form of a question... The other day I saw a thread where someone asked about overrideable properties and nobody offered the advice that properties are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.