473,652 Members | 2,965 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple date time question!

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.ParseE xact and DateTimeFormatI nfo but
failed, most examples I see convert the final result to a string... I
dont want that!

Thanks for help :)

Mar 27 '07 #1
7 1991
On Tue, 27 Mar 2007 16:02:34 -0700, JamesG <ma********@gma il.comwrote:
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.ParseE xact and DateTimeFormatI nfo 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
Mar 27 '07 #2
On Mar 28, 12:14 am, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Tue, 27 Mar 2007 16:02:34 -0700, JamesG <mailmeh...@gma il.comwrote:
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.ParseE xact and DateTimeFormatI nfo 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

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

Mar 27 '07 #3
"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
Mar 27 '07 #4
On Mar 28, 12:54 am, "Bill Butler" <qwe...@asdf.co mwrote:
"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

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!

Mar 28 '07 #5
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


"JamesG" wrote:
On Mar 28, 12:14 am, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Tue, 27 Mar 2007 16:02:34 -0700, JamesG <mailmeh...@gma il.comwrote:
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.ParseE xact and DateTimeFormatI nfo 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


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

Mar 28 '07 #6
On Mar 28, 2:56 am, Peter Bromberg [C# MVP]
<pbromb...@yaho o.yabbadabbadoo .comwrote:
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

"JamesG" wrote:
On Mar 28, 12:14 am, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Tue, 27 Mar 2007 16:02:34 -0700, JamesG <mailmeh...@gma il.comwrote:
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.ParseE xact and DateTimeFormatI nfo 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
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
Indeed, I see my misunderstandin g. I now have a single var holding the
format I require, however it's a bit of a hack...
DateTime waypReq.datetim e =
Convert.ToDateT ime(System.Date Time.Now.ToStri ng());

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

Mar 28 '07 #7

"JamesG" <ma********@gma il.comwrote in message
news:11******** **************@ d57g2000hsg.goo glegroups.com.. .
On Mar 28, 2:56 am, Peter Bromberg [C# MVP]
<pbromb...@yaho o.yabbadabbadoo .comwrote:
<snip>
>
Indeed, I see my misunderstandin g. I now have a single var holding the
format I require, however it's a bit of a hack...
DateTime waypReq.datetim e =
Convert.ToDateT ime(System.Date Time.Now.ToStri ng());
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

Mar 29 '07 #8

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

Similar topics

6
3782
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am trying to read a flatfile. In COBOL, my simple file layout and READ statement would look like below. Question: what is the standard, simple coding convention for reading in a flatfile - one record at a time?? SCANF does not work because of...
2
8387
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the client side javacript code for form validation and client side editing capabilities in order to save...
18
3026
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How ??
6
12541
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a calendar control to allow my users to enter a date but I need them to enter a time as well. It doesn't look like the calendar control will allow times to be entered so I was thinking of having two text boxes. One text box would contain the date...
5
1812
by: devagupt | last post by:
I have a question . I have a Chart which i run from a query. The chart has 3 fields Line , Date , Time in mins. The purpose of the chart is to display the sum of all the "time in mins" in a given "line" for a week( from date to date). In the query i am trying to sum all the "time in mins" for a given line and display it as a sum. How should i do that?The query should also have the date, sum of time in mins for a given line. This info...
11
1995
by: Ground21 | last post by:
Hello. I'm new // sorry for my english :) I have to write simple program i c++. But I don't know how to code src - program should know it's name (unit1.exe so the name is "unit1" or "unit1.exe" and it's full path (with volume name - c:\programs). Which commends of c++ should I use? (please do not redirect me to 'help', because I must have some "start point" ! :)
5
2834
by: GregO | last post by:
I am new to ASP and would like to know if anyone has a page that will display username, time, IP TIA - Grego
6
3933
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
4536
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 evaluates to true when the time is not greater than dtmTime #9:32:34 PM# Why is that? and How can I get this to work? Brian
0
8370
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8283
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
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...
0
8704
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8470
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
8590
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
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2707
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
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.