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

DateTime

A.M
Hi,

I know we can assigne year, month and day to a DateTime value by the
constructor like

Dim dt As DateTime = New DateTime(2003,8,1)

How can i assign value by year, month and day? I am looking for a function
like this:

st = SetDateTime(2002,7,2)

Is there any way to that without creating a new DateTime object ?

Thanks,
Ali



Nov 20 '05 #1
5 8615
Hi A.M,

I'm not quite sure to your question. You need to set a DateTime value by
this function, but what's the type of the return value? Did you mean
st.SetDateTime(2002,7,2)?

Could you please provide slightly more information about what you are going
to do, it would be much easier to help you find ways to achieve that.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 20 '05 #2
Hello,

"A.M" <IH*******@sapm123.com> schrieb:
I know we can assigne year, month and day to a DateTime
value by the constructor like

Dim dt As DateTime = New DateTime(2003,8,1)

How can i assign value by year, month and day? I am
looking for a function like this:

st = SetDateTime(2002,7,2)

Is there any way to that without creating a new DateTime
object ?


What's the porblem with creating a new object?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #3
"A.M" <IH*******@sapm123.com> schrieb
I know we can assigne year, month and day to a DateTime value by
the constructor like

Dim dt As DateTime = New DateTime(2003,8,1)

How can i assign value by year, month and day? I am looking for a
function like this:

st = SetDateTime(2002,7,2)

Is there any way to that without creating a new DateTime object ?


You mean you want to _change_ the date/time of an existing DateTime object?
Unfortunately, the answer is: no, it is not possible. If you are concerned
about the performance, it is no a big deal, because the only field of a
datetime object is/are the Ticks (int64).
--
Armin

Nov 20 '05 #4
A.M

There is no problem to create a new DateTime object and leave it to GC
Why such a perfect class suffers from lack of method like
st.SetTime(year,month,day) ?
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:Om**************@TK2MSFTNGP12.phx.gbl...
Hello,

"A.M" <IH*******@sapm123.com> schrieb:
I know we can assigne year, month and day to a DateTime
value by the constructor like

Dim dt As DateTime = New DateTime(2003,8,1)

How can i assign value by year, month and day? I am
looking for a function like this:

st = SetDateTime(2002,7,2)

Is there any way to that without creating a new DateTime
object ?


What's the porblem with creating a new object?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #5
A.M
Oops, My mistake!

Thanks,
Ali
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:%2********************@TK2MSFTNGP10.phx.gbl.. .
A.M,
I hope you realize that DateTime is an immutable Structure, not a Class!

Being a Structure means it is a value type and has value semantics, being
immutable means it has full value semantics.

Which means to change a value on a DateTime variable you need to create a
new DateTime 'value'. Being a Structure means that this DateTime 'value'
exists on the stack, not the heap. Hence the GC does not collection DateTime objects.

So the following statement:
> Dim dt As DateTime = New DateTime(2003,8,1)

Does not create an object on the heap that the GC needs to collection

later.
This is (partially) explained at:
http://msdn.microsoft.com/library/de...guidelines.asp
(following the links on that page for more details)

Of course if a Class has an instance DateTime field, that DateTime 'value'
exists on the heap as an integral part of that object. Or if a DateTime
'value' is passed to an Object parameter, the 'value' will be boxed, at that point it is effectively an object.

Hope this helps
Jay

"A.M" <IH*******@sapm123.com> wrote in message
news:OB*************@TK2MSFTNGP11.phx.gbl...

There is no problem to create a new DateTime object and leave it to GC
Why such a perfect class suffers from lack of method like
st.SetTime(year,month,day) ?
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:Om**************@TK2MSFTNGP12.phx.gbl...
Hello,

"A.M" <IH*******@sapm123.com> schrieb:
> I know we can assigne year, month and day to a DateTime
> value by the constructor like
>
> Dim dt As DateTime = New DateTime(2003,8,1)
>
> How can i assign value by year, month and day? I am
> looking for a function like this:
>
> st = SetDateTime(2002,7,2)
>
> Is there any way to that without creating a new DateTime
> object ?

What's the porblem with creating a new object?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet



Nov 20 '05 #6

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

Similar topics

4
by: Max M | last post by:
# -*- coding: latin-1 -*- """ I am currently using the datetime package, but I find that the design is oddly asymmetric. I would like to know why. Or perhaps I have misunderstood how it...
16
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am...
15
by: Fritz Switzer | last post by:
I'd like to have a string assigned the value of a DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" format. For example: DateTime.Now.AddMinutes(30) returns "00:30" ...
3
by: Andrew S. Giles | last post by:
Hello, I am importing a flat text file, and putting it into a datagrid for display on a form. Currently the users have their dates and times seperated. I have two fields, therefore in the...
6
by: Ante Perkovic | last post by:
Hi, How to declare datetime object and set it to my birthday, first or last day of this month or any other date. I can't find any examples in VS.NET help! BTW, what is the difference...
5
by: I am Sam | last post by:
I have created this DateTime object and instanced it I think correctly DateTime myClubNow1=new...
26
by: Reny J Joseph Thuthikattu | last post by:
Hi, I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a miniute to it.How can i do that? by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004 12:00 AM'...
11
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
9
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.