simple date time question!

J

JamesG

Hi,

I need to convert the current time to the format "hh:mm:ss" and date
to the format "yyyy-MM-dd".
The result of both conversions needs to be of System.DateTime format.

I've tried using DateTime.ParseExact and DateTimeFormatInfo but
failed, most examples I see convert the final result to a string... I
dont want that!

Thanks for help :)
 
P

Peter Duniho

I need to convert the current time to the format "hh:mm:ss" and date
to the format "yyyy-MM-dd".
The result of both conversions needs to be of System.DateTime format.

I've tried using DateTime.ParseExact and DateTimeFormatInfo but
failed, most examples I see convert the final result to a string... I
dont want that!

I don't understand your question. The formats "hh:mm:ss" and "yyyy-MM-dd"
are string formats. You can't ask to convert time into those formats and
then say that you don't want a string.

Pete
 
J

JamesG

I don't understand your question. The formats "hh:mm:ss" and "yyyy-MM-dd"
are string formats. You can't ask to convert time into those formats and
then say that you don't want a string.

Pete


Hi Pete,

I have 2 seperate vars defined as:
System.DateTime time;
System.DateTime date;

Quite simply, I need the time var to reflect only the current time
(i.e. 15:34:22) and date var (i.e. 2007-28-3).
I can quite easily assign the full date/time using .Now but this is
not good enough.
Is what I require at all possible?

Thanks for your time
 
B

Bill Butler

"> I have 2 seperate vars defined as:
System.DateTime time;
System.DateTime date;

Quite simply, I need the time var to reflect only the current time
(i.e. 15:34:22) and date var (i.e. 2007-28-3).
I can quite easily assign the full date/time using .Now but this is
not good enough.
Is what I require at all possible?

Perhaps you can give a sample of how you intend to use these vars.
A snippet of code demonstrating how you intend to populate these
variables and use these variables should suffice.

The reason I am asking is that the usage may affect the best design
decisions.

For instance
Are the date and time variables in you sample relating to a single
DateTime or are they unrelated?
If they relate to a single DateTime why do you need them separate?
Are you comparing Dates/Times?
...

Bill
 
J

JamesG

"> I have 2 seperate vars defined as:



Perhaps you can give a sample of how you intend to use these vars.
A snippet of code demonstrating how you intend to populate these
variables and use these variables should suffice.

The reason I am asking is that the usage may affect the best design
decisions.

For instance
Are the date and time variables in you sample relating to a single
DateTime or are they unrelated?
If they relate to a single DateTime why do you need them separate?
Are you comparing Dates/Times?
...

Bill


Hi, it is for a web service, the vars are declared in the web
reference proxy.
To save time and hassle, I have just edited the wsdl file to combine
these fields!

Sorry for wasting your time!
 
G

Guest

James,
I believe the difficulty here revolves around an incomplete understanding of
the DateTime object. All DateTime objects contain a complete year, month,
day, hour, seconds, milliseconds.

Consequently it would be impossible to make 2 DateTime variables one which
only holds the calendar date and one which only holds the hours, minutes,
seconds etc.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
 
J

JamesG

James,
I believe the difficulty here revolves around an incomplete understanding of
the DateTime object. All DateTime objects contain a complete year, month,
day, hour, seconds, milliseconds.

Consequently it would be impossible to make 2 DateTime variables one which
only holds the calendar date and one which only holds the hours, minutes,
seconds etc.
Peter

Indeed, I see my misunderstanding. I now have a single var holding the
format I require, however it's a bit of a hack...
DateTime waypReq.datetime =
Convert.ToDateTime(System.DateTime.Now.ToString());

I don't want the fractions or timezone etc in the var so i'm forced to
do that.. there must be a more efficient way.. surely!?

Thanks all
 
B

Bill Butler

JamesG said:
On Mar 28, 2:56 am, Peter Bromberg [C# MVP]
<[email protected]> wrote:
Indeed, I see my misunderstanding. I now have a single var holding the
format I require, however it's a bit of a hack...
DateTime waypReq.datetime =
Convert.ToDateTime(System.DateTime.Now.ToString());

DateTime dt = DateTime.Now;
would achieve the same thing
What are you trying to achieve?

I don't want the fractions or timezone etc in the var so i'm forced to
do that.. there must be a more efficient way.. surely!?

I don't understand this last sentence at all. What do you mean by
"fractions or timezone etc" and why do you think your "Hack" would
change that?

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top