473,320 Members | 2,193 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,320 software developers and data experts.

help with datetime

In the database, we are storing time in 3 columns: hours, Minutes and
AM,PM.
After retrieving it from the database, I want to load these values into
a DateTime variable. I haven't had much success.

I would appreciate if anyone can help me in this matter

thank you
MB

Jun 28 '06 #1
4 1684
1. Consider changing your database to store them using a real datetime
datatype instead
2. Consider changing your database to store them using a real datetime
datatype instead
3. Consider changing your database to store them using a real datetime
datatype instead
4. Ok, maybe you can't change your database :-) Try this:

Dim hours As String = "07"
Dim minutes As String = "23"
Dim ampm As String = "am"

Dim s As String = hours & ":" & minutes & " " & ampm
Dim dt As DateTime = DateTime.TryParse(s, "hh\:mm tt", Nothing)

Note that the format string in this sample ("hh\:mm tt") assumes leading
zeroes for single digit hours and minutes. If you don't have that you can
use "h\:m tt", "h\:mm tt" or "hh\:m tt" instead (depending on what you
have). See DateTimeFormatInfo for more info on the format string.

/claes
"Mohan" <ka******@gmail.com> wrote in message
news:11**********************@x69g2000cwx.googlegr oups.com...
In the database, we are storing time in 3 columns: hours, Minutes and
AM,PM.
After retrieving it from the database, I want to load these values into
a DateTime variable. I haven't had much success.

I would appreciate if anyone can help me in this matter

thank you
MB

Jun 28 '06 #2
First of all storing hours, minutes, and AM/PM is not sufficient to
correctly reproduce a DateTime object.

public DateTime (int year,int month,int day,int hour,int minute,int
second,int millisecond)

Since in the database you are also storing AM/PM, so I assume you are
storing hours in 12 hour format. So before calling DateTime constructor, set
the hour field to 24 hours format.
If (PM) { hour = (hr_from_DB < 12 ? (hr_from_DB + 12) : 0) ); } <- Note that
the day field will still be wrong.

DateTime dt = new DateTime(System.DateTime.Today.Year,
System.DateTime.Today.Month, System.DateTime.Today.Day, hour, 50, 0, 0);

"Mohan" <ka******@gmail.com> wrote in message
news:11**********************@x69g2000cwx.googlegr oups.com...
In the database, we are storing time in 3 columns: hours, Minutes and
AM,PM.
After retrieving it from the database, I want to load these values into
a DateTime variable. I haven't had much success.

I would appreciate if anyone can help me in this matter

thank you
MB

Jun 28 '06 #3
Mohan,

1. Consider changing your database to store them using a real datetime
datatype instead
2. Consider changing your database to store them using a real datetime
datatype instead
3. Consider changing your database to store them using a real datetime
datatype instead
4. Ok, maybe you can't change your database :-) Than you can try this:

\\\
Dim dtm As New DateTime
dtm = dtm.AddHours(CDbl("11"))
dtm = dtm.AddMinutes(CDbl("50"))
If "PM" = "PM" Then dtm = dtm.AddHours(12)
///

Althouhg I would use one of the first 3 advices.

Cor

"Mohan" <ka******@gmail.com> schreef in bericht
news:11**********************@x69g2000cwx.googlegr oups.com...
In the database, we are storing time in 3 columns: hours, Minutes and
AM,PM.
After retrieving it from the database, I want to load these values into
a DateTime variable. I haven't had much success.

I would appreciate if anyone can help me in this matter

thank you
MB

Jun 28 '06 #4
"Mohan" <ka******@gmail.com> schrieb:
In the database, we are storing time in 3 columns: hours, Minutes and
AM,PM.
After retrieving it from the database, I want to load these values into
a DateTime variable. I haven't had much success.


As others have already said, change the format you are storing the date
values in. You may want to take a look at the 'SqlDateTime' type too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 28 '06 #5

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

Similar topics

2
by: Keith | last post by:
I am having a problem creating a many-to-many-to-many type relationship. It works fine, but when I create a view to query it and test it, it does not generate the results I expected. Below...
9
by: Martin | last post by:
Hello, I'm new with triggers and I can not find any good example on how to do the following: I have two tables WO and PM with the following fields: WO.WONUM, VARCHAR(10) WO.PMNUM,...
4
by: Mingus Tsai | last post by:
Hello- please help with unpickling problem: I am using Python version 2.3.4 with IDLE version 1.0.3 on a Windows XPhome system. My problem is with using cPickle to deserialize my pickled...
15
by: Cesar Ronchese | last post by:
Hi, I built the sample code showing the problem with dates when viewed at different machines, different Time Zones and transported via Remoting. The zip can be downloaded here: ...
0
by: Brian Henry | last post by:
Ok I've never implemented a snap location before so I dont really know what im doing wrong here... anyways, I am making a custom slider control that takes dates as its values instead of integers......
22
by: KitKat | last post by:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7, and Cam 8. Well it does that but it also needs to change the file name to the same folder where the file is being...
13
by: sd00 | last post by:
Hi all, can someone give me some coding help with a problem that *should* be really simple, yet I'm struggling with. I need the difference between 2 times (Target / Actual) However, these times...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
12
by: colincolehour | last post by:
I am new to Python and am working on my first program. I am trying to compare a date I found on a website to todays date. The problem I have is the website only shows 3 letter month name and the...
2
by: rizal123456789 | last post by:
any can help me. iam new in oracle. i have a table like this key || datetime || amount where key is varchar(7) and amount is number i want make some view that show sum of amount per a...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.