473,386 Members | 1,748 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,386 software developers and data experts.

Time Part of DateTime Data Type

Hello ,

I have a sub that gets all records in a [Time] table. Then displays the
times in a drop-down list (ddlStartTime). My problem is that the ddl contain
the date AND time. i.e. 9:00 AM in the table is 1/1/1899 9:00:00 AM in the
ddl.

How do I get JUST the Time in format 9:00 AM??

Please I have been at this now for over 2 days and I can't seem to get
anywhere with it.

Thanks,
Mark
Jul 21 '05 #1
9 1869
Hi,
Try with This One.............

MessageBox.Show(CType("1/1/1899 9:00:00 AM", DateTime).ToShortTimeString)

Regards,
Ritesh

--
Message posted via http://www.dotnetmonster.com
Jul 21 '05 #2
Thanks Ritesh for the reply. However I am using web forms. I forgot to
mention that. Sorry.

Mark

"Ritesh Jain via DotNetMonster.com" wrote:
Hi,
Try with This One.............

MessageBox.Show(CType("1/1/1899 9:00:00 AM", DateTime).ToShortTimeString)

Regards,
Ritesh

--
Message posted via http://www.dotnetmonster.com

Jul 21 '05 #3
Dim s as string
s=CType("1/1/1899 9:00:00 AM", DateTime).ToShortTimeString

s will be "9:00 AM"

What's the problem?

"MGRIDEOUT" <MG*******@discussions.microsoft.com> wrote in message
news:EA**********************************@microsof t.com...
Thanks Ritesh for the reply. However I am using web forms. I forgot to
mention that. Sorry.

Mark

"Ritesh Jain via DotNetMonster.com" wrote:
Hi,
Try with This One.............

MessageBox.Show(CType("1/1/1899 9:00:00 AM",
DateTime).ToShortTimeString)

Regards,
Ritesh

--
Message posted via http://www.dotnetmonster.com

Jul 21 '05 #4
MGRIDEOUT <MG*******@discussions.microsoft.com> wrote:
I have a sub that gets all records in a [Time] table. Then displays the
times in a drop-down list (ddlStartTime). My problem is that the ddl contain
the date AND time. i.e. 9:00 AM in the table is 1/1/1899 9:00:00 AM in the
ddl.

How do I get JUST the Time in format 9:00 AM??

Please I have been at this now for over 2 days and I can't seem to get
anywhere with it.


I'd suggest using theDateTime.ToString("hh:mm tt"), if you want to
definitely use that format rather than the locale-specific short time
format.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #5
Greg,

I thought you where an American who had read that great book from Lederer
and Burdick (Americans).

\\\
Threading.Thread.CurrentThread.CurrentCulture = _
New Globalization.CultureInfo("en-US")
Dim s As String = CType("1/1/1899 9:00:00 AM", DateTime).ToShortTimeString
Threading.Thread.CurrentThread.CurrentCulture = _
Globalization.CultureInfo.InstalledUICulture
///

With a friendly smile on my face of course

(Did you see those samples I made about that displaymember by the way?, I
did it special because we where talking about it)

Cor
Jul 21 '05 #6
Jon,

I'd suggest using theDateTime.ToString("hh:mm tt"), if you want to
definitely use that format rather than the locale-specific short time
format.

In my humble opinion does that not work in cultures where AM and PM is not
in the standard culture setting. I tried it before I sent my sample part,
because I thought as well that it would work forever but it did not. (Your
"hh:mm tt" is by the way the direct translation from what Greg has sent in
cultures where AM/PM is used.)

It is written on this page.
http://msdn.microsoft.com/library/de...natortopic.asp

Cor
Jul 21 '05 #7
I was only reacting to the silliness of saying Ritesh's idea won't work with
a webform. Presumedly because of the msgbox call.

But it is true I should've been thinking more globally. :^)
(Did you see those samples I made about that displaymember by the way?, I
did it special because we where talking about it)
Which thread? Must've missed it.

Greg

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OM****************@TK2MSFTNGP10.phx.gbl... Greg,

I thought you where an American who had read that great book from Lederer
and Burdick (Americans).

\\\
Threading.Thread.CurrentThread.CurrentCulture = _
New Globalization.CultureInfo("en-US")
Dim s As String = CType("1/1/1899 9:00:00 AM", DateTime).ToShortTimeString
Threading.Thread.CurrentThread.CurrentCulture = _
Globalization.CultureInfo.InstalledUICulture
///

With a friendly smile on my face of course

(Did you see those samples I made about that displaymember by the way?, I
did it special because we where talking about it)

Cor

Jul 21 '05 #8
(Did you see those samples I made about that displaymember by the way?, I
did it special because we where talking about it)


Which thread? Must've missed it.

http://groups-beta.google.com/group/...5153838e3ef233

Jul 21 '05 #9
Cor Ligthert <no************@planet.nl> wrote:
I'd suggest using theDateTime.ToString("hh:mm tt"), if you want to
definitely use that format rather than the locale-specific short time
format.
In my humble opinion does that not work in cultures where AM and PM is not
in the standard culture setting.


You're right that it doesn't work in cultures where the AM designator
is not used at all. However, the designator may not be used in the
standard short time display, even if it's still present.
I tried it before I sent my sample part,
because I thought as well that it would work forever but it did not. (Your
"hh:mm tt" is by the way the direct translation from what Greg has sent in
cultures where AM/PM is used.)


Well, it may be - it may not be. For instance, some cultures may have
AM and PM *defined* (i.e. they *can* use the AM/PM designators) but
choose not to use them.

In other words, there are cultures where using ToShortTimeString
returns "20:05" where my code would return "8:05 PM". In fact, not only
are some cultures like that, but I happen to live in one :)

I've just run the following program:
using System;
class Test
{
static void Main()
{
DateTime dt = DateTime.Now;

Console.WriteLine (dt.ToString("hh:mm tt"));
Console.WriteLine (dt.ToShortTimeString());
}
}

and the results are:
10:19 PM
22:19

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #10

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

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
8
by: Chris Dunaway | last post by:
When using a PropertyGrid, I have an object with a Date property, but I am only interested in the Time portion. How do I make the PropertyGrid allow editing the time only? Just the hours and...
4
by: M. Uppal | last post by:
How do i convert fraction to time in c#. I need to convert 0.25 to time. Excel does this by using Selection.NumberFormat = "h:mm:ss;@" of the Cell Format function. thanks, M. Uppal
5
by: ad | last post by:
I have a tabls of SQL 2000, about the data of student. The data is migrate from another databse, There is a field called birthday, it stores the data with the formate like: 1994/11/03 AM 02:09:00...
9
by: Shapper | last post by:
Hello, I created a dataset from a XML file. One of the dataset fields is . In an ASP:Repeater I am displaying the field. <%# DataBinder.Eval(Container.DataItem, "pubDate", "{0:f}") %> The...
2
by: DWalker | last post by:
In Visual Studio (Visual Basic) .NET 2002, I noticed that this: Dim Elapsed as DateTime = Now - Now gives a "compile time" error (error in the IDE), saying that the '-' operator is not...
7
by: Brett Edman | last post by:
I created a UTC clock using this: UTCTime = MyTime.ToUniversalTime() Now that we've turned the clocks ahead 1 hour for daylight savings time, the clock is reporting the wrong UTC time. It is...
6
by: Geoff Cox | last post by:
Hello, at the moment I can add the combined date and time into MySQL using php $dt1 = date("Y-m-d H:i:s"); is it possible to add the date and time separately? I thought it might be
25
by: Brian | last post by:
I have a datetimepicker formated for just time, the user selects the time. I want to compare if that time is between midnight and 8 am dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM# this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.