473,804 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1700
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.TryPar se(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 DateTimeFormatI nfo for more info on the format string.

/claes
"Mohan" <ka******@gmail .com> wrote in message
news:11******** **************@ x69g2000cwx.goo glegroups.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.goo glegroups.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(CD bl("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.goo glegroups.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
908
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 if the DDL for the tables and the SQL for the view.
9
3464
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, VARCHAR(10) WO.PROBLEMCODE, VARCHAR(8)
4
2835
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 arrays of datetime.datetime instances. The following is the code I have written: import cPickle, datetime import Numeric
15
2023
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: www.carsoftnet.com.br/temp/sample_error_date.zip
0
1910
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... then taking that date range and finding dates specifiec between them (in a list of dates) and putting snap marks, so if you slide it near one of them it should snap to that tick, but that part i cant figure out. the rest seems ok so far... here...
22
2206
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 grabbed, BUT it doesn't. I have tried and tried.....please help example: C:\Projects\Darryl\Queue Review Files\2-24\Cam 7\Cam7-20060224170000-01.jpg Cam7 but all I keep getting is Cam1, as the beginning of the jpg name,...:( HELP!
13
2155
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 will fall somewhere between a Start & End time Further more, there will be Break & Lunch times between Start & End. Example... Start 08:00 Break start 10:30
5
3796
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 List<RoleData> GetRoles() { return GetRoles(null, false); }
12
5567
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 date. Example: Jun 15 How would I go about comparing that to a different date? The purpose of my program is to load a webpage and see if the content on the front page is fresh or stale as in older than a few days. Any help in the right direction...
2
1606
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 mounth and look like this
0
10595
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10089
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9171
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7634
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.