Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Date Literals That Include Milliseconds

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nathan Sokalski - 26 Aug 2007 00:20 GMT
I have a control uses the date and time, including milliseconds. I want to
be able to enter this information as an attribute in the *.aspx page.
Because all attributes are entered as strings in the *.aspx page, I need a
recognizable date/time string that includes the date and time, including
milliseconds. Can somebody tell me the best format to do this in? Thanks.
(NOTE: The date/time data is coming from a databound field from an SQL
Server database.)
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

Cor Ligthert[MVP] - 26 Aug 2007 06:15 GMT
Nathan,

Because there are so many processes bussy mostly, is the windows operating
system probably not that accurate that you can get the real time in
milliseconds.

However the datetime.millisecond gives something back what reaches that the
most, but that is not in a literal, so just appending the toString with the
& will probably be the best.

Cor

>I have a control uses the date and time, including milliseconds. I want to
>be able to enter this information as an attribute in the *.aspx page.
[quoted text clipped - 3 lines]
>(NOTE: The date/time data is coming from a databound field from an SQL
>Server database.)
Mark Rae [MVP] - 26 Aug 2007 09:13 GMT
>I have a control uses the date and time, including milliseconds. I want to
>be able to enter this information as an attribute in the *.aspx page.
[quoted text clipped - 3 lines]
>(NOTE: The date/time data is coming from a databound field from an SQL
>Server database.)

DateTime dtmDateTime = <however you get your datetime variable>;
string strDateTime = dtmDateTime.ToString("dd MMM yyyy HH:mm:ss:fff");

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Nathan Sokalski - 26 Aug 2007 22:58 GMT
You have me confused; the examples you give are in the codebehind, I am
looking for a string that can be assigned to a datetime attribute that
includes milliseconds. For example:

<cc1:TimePicker id="timepkr" runat="server" SelectedTime="datetime string
with milliseconds">

SelectedTime is a property of type DateTime, so I need to know how to format
the string I assign to it. The examples you gave assign a String that you
didn't show me to a DateTime and assign a DateTime to a String. You did not
tell me the piece of information I am looking for: What format is the string
in when you assign it to the DateTime? Thanks.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

>
>>I have a control uses the date and time, including milliseconds. I want to
[quoted text clipped - 7 lines]
> DateTime dtmDateTime = <however you get your datetime variable>;
> string strDateTime = dtmDateTime.ToString("dd MMM yyyy HH:mm:ss:fff");
Mark Rae [MVP] - 26 Aug 2007 23:13 GMT
> SelectedTime is a property of type DateTime

Er, no it isn't - the following MSDN page lists the properties of a DateTime
variable:
http://msdn2.microsoft.com/en-us/library/system.datetime_properties(VS.80).aspx

There is no SelectedTime property...

You said: "(NOTE: The date/time data is coming from a databound field from
an SQL Server database.)"

The code I gave you will accept a DateTime variable (which could be fetched
from a data object) and will then cast it to a string which includes
milliseconds...

If that's not what you require, then please explain in more detail...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Nathan Sokalski - 27 Aug 2007 01:04 GMT
I'm sorry, I think I was unclear in the way I phrased that statement. When I
said "SelectedTime is a property of type DateTime", I meant that my Control
has a property named SelectedTime that is a DateTime, like the following:

Public Property SelectedTime() As DateTime

But back to my original question, are you saying that if I do something
like:

<cc1:TimePicker id="timepkr" runat="server" SelectedTime='<%#
DataBinder.Eval(Container.DataItem,"myfield") %>'>

It will assign the entire date & time including milliseconds from the
database to my SelectedTime property? The reason this concerned me is
because the single quotes around the databinding expression made me think
the value from the database was converted to a String before being assigned
to the property. Is this true, or will the exact value from the database be
assigned to the property without being converted to a string first? Thanks.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

>> SelectedTime is a property of type DateTime
>
[quoted text clipped - 12 lines]
>
> If that's not what you require, then please explain in more detail...
Mark Rae [MVP] - 27 Aug 2007 09:32 GMT
> I'm sorry, I think I was unclear in the way I phrased that statement. When
> I said "SelectedTime is a property of type DateTime", I meant that my
> Control has a property named SelectedTime that is a DateTime

I see...

> But back to my original question, are you saying that if I do something
> like:
[quoted text clipped - 9 lines]
> database be assigned to the property without being converted to a string
> first?

What happened when you tried it...?

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

rowe_newsgroups - 27 Aug 2007 11:37 GMT
> I have a control uses the date and time, including milliseconds. I want to
> be able to enter this information as an attribute in the *.aspx page.
[quoted text clipped - 6 lines]
> Nathan Sokalski
> njsokal...@hotmail.comhttp://www.nathansokalski.com/

I believe you can use:

   myDateTime.ToString("M/d/yyyy HH:mm:ss:fff")

To print a date something like:

   8/27/2007 06:37:13:0257

Thanks,

Seth Rowe
Mark Rae [MVP] - 27 Aug 2007 11:40 GMT
>    myDateTime.ToString("M/d/yyyy HH:mm:ss:fff")

See my first reply in this thread...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

rowe_newsgroups - 27 Aug 2007 13:41 GMT
> >    myDateTime.ToString("M/d/yyyy HH:mm:ss:fff")
>
[quoted text clipped - 3 lines]
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net

Sorry Mark - didn't realize I repeated you. Apparently, this
originally multiposted thread turned into a crossposted thread. All
your earlier posts are only on the
microsoft.public.dotnet.framework.aspnet newsgroup and not the
microsoft.public.dotnet.languages.vb newsgroup from which I am
posting.

Thanks,

Seth Rowe
Mark Rae [MVP] - 27 Aug 2007 13:45 GMT
> Sorry Mark - didn't realize I repeated you. Apparently, this
> originally multiposted thread turned into a crossposted thread. All
> your earlier posts are only on the
> microsoft.public.dotnet.framework.aspnet newsgroup and not the
> microsoft.public.dotnet.languages.vb newsgroup from which I am
> posting.

Ah right - the OP does have a habit of cross-posting, which I usually
correct if I remember...

X-posted deliberately to microsoft.public.dotnet.languages.vb

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Nathan Sokalski - 29 Aug 2007 12:48 GMT
Did anybody read the Subject of this thread? It says Date LITERALS, not Date
Formatting. This means I want a Date String that already is a String that I
can assign to a Date Object. My reason for needing this is that I need to
declaratively assign a date to a Control Property in the *.aspx file using
Attributes. Any ideas? Thanks.

>>    myDateTime.ToString("M/d/yyyy HH:mm:ss:fff")
>
> See my first reply in this thread...
Mark Rae [MVP] - 29 Aug 2007 13:03 GMT
(Cross-posting and top-posting corrected)

> Did anybody read the Subject of this thread?

Ahem...

> It says Date LITERALS, not Date Formatting. This means I want a Date
> String that already is a String that I can assign to a Date Object. My
> reason for needing this is that I need to declaratively assign a date to a
> Control Property in the *.aspx file using Attributes. Any ideas? Thanks.

string strDateLiteral = "29 Aug 2007 15:59:13:123";
DateTime dtmDate = DateTime.ParseExact(strDateLiteral, "dd MMM yyyy
HH:mm:ss:fff");

http://msdn2.microsoft.com/en-us/library/system.datetime.parseexact(vs.80).aspx

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

rowe_newsgroups - 29 Aug 2007 14:13 GMT
> Did anybody read the Subject of this thread? It says Date LITERALS, not Date
> Formatting.

Seth's first rule of newsgroups: Act like an ***hole - receive no more
help.

With that said, I consider this a warning and try to help you again.

> This means I want a Date String that already is a String that I
> can assign to a Date Object.

I don't see the problem - you can assign the string for the Control's
property like this:

   <uc1:DateUC ID="theDateUC" runat="server" TheDateTime='8/29/2007
09:01:52.257' />

In my usercontrol I created the property looks like:

   public DateTime TheDateTime {
       get {
           return DateTime.Parse(this.dateTimeLiteral.Text);
       }
       set {
           this.dateTimeLiteral.Text = value.ToString("M/d/yyyy
HH:mm:ss:fff");
       }
   }

And everything showed up in my literal control just fine.

Thanks,

Seth Rowe
Mark Rae [MVP] - 29 Aug 2007 14:24 GMT
>> Did anybody read the Subject of this thread? It says Date LITERALS, not
>> Date
>> Formatting.
>
> Seth's first rule of newsgroups: Act like an ***hole - receive no more
> help.

The OP is well-known for that - he's a recent graduate who firmly believes
that the world owes him a living, and that these newsgroups are his own
private helpdesk...

Maybe he'll grow up one day...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

rowe_newsgroups - 29 Aug 2007 14:37 GMT
> The OP is well-known for that - he's a recent graduate who firmly believes
> that the world owes him a living, and that these newsgroups are his own
> private helpdesk...
>
>Maybe he'll grow up one day...

Thanks for the warning Mark, I'd go ahead and killfile him now if I
didn't insist on using google groups as my newsreader.

Thanks,

Seth Rowe
Cor Ligthert[MVP] - 30 Aug 2007 05:48 GMT
Nathan,

Maybe you can next time write a message like your subject, putting "Wood" in
your subject and start than to write about "Bush" does not give good
information.

This is what you wrote.

>>I need a recognizable date/time string that includes the date and time,
>>including
milliseconds.

This does not mean (probably beside in your mind)

>>a Date String that already is a String that I can assign to a Date Object.

Although it is for me completely not to understand what you want.

A DateTime literal is fixed in one format, which is based on the USA time
and almost never usable in the rest of the world or by internet sites which
are not only for the USA (In fact can that be all COM, ORG, NET, TV and more
of those sites). Therefore it probably even for most not recognisable what
you want in these very much international newsgroups.

Outside the USA probably nobody uses them.

Cor

> Did anybody read the Subject of this thread? It says Date LITERALS, not
> Date Formatting. This means I want a Date String that already is a String
[quoted text clipped - 5 lines]
>>
>> See my first reply in this thread...

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.