473,513 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Help with DateTime in C#

62 New Member
Hi There.

I have a variable called dtDate. I want to assign today\s date to it in short format:

E.G.: 2007/12/07

However I get it in the following format:

2007/12/07 0:00:00 - It includes the time.

How can I just get the date?

I have tried: the dtDate.ToShortString() etc, but with no success.

Thanks,

Lóan
Dec 7 '07 #1
6 1959
nateraaaa
663 Recognized Expert Contributor
What about .ToShortDateString()? If you want to rearrange the position of the year, month, date you will need to use String.Format.

DateTime on msdn

Nathan
Dec 7 '07 #2
LoanB
62 New Member
Hi Nathan

Appologies I meant .ToShortDateString() not ".ToShortString()"

Still returns the time as well.
Dec 7 '07 #3
Plater
7,872 Recognized Expert Expert
DateTime objects will always store a "date and time"
You can format the string version of it with .ToString()

So:
Expand|Select|Wrap|Line Numbers
  1. string mydatestring="";
  2. mydatestring=DateTime.Now.ToString("yyyyMMdd");
  3. //mydatestring is now "20071207"
  4.  
Dec 7 '07 #4
LoanB
62 New Member
Hey guys

I feel like a bit of an A*s, In my database the field name was "Dates" and in the code I had "Date" - natuarally not going to work. Hence the problem I had is now fixed.

As my field type is DateTime in the Database I could not use ToShortDateString(), us assign it to a String.

Well all is well, and my C# knowledge is expanding

Thanks Nathan and Plater!
Dec 7 '07 #5
drutchlin
1 New Member
To get just todays date use DateTime.Today()
Dec 7 '07 #6
sumitgupta10
13 New Member
Hi,
To get just todays date,try this one,
DateTime.Now.ToShortDateString()
Dec 10 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1925
by: nephish | last post by:
Hey there, i am doing a plotting application. i am using mxRelativeDateTimeDiff to get how much time is between date x and date y now what i need to do is divide that time by 20 to get 20 even...
2
7770
by: A Programmer | last post by:
I can't believe I have never run into this before but, I have an object that has a property of type DateTime. A collection of these objects are used to populate my DataGrid. In DateTime format they...
2
1274
by: Chris | last post by:
Hi, I have a table with a field that should store date and time. The table column data type is datetime. I am trying Dim dt as datetime ...
5
2661
by: The Pig | last post by:
Got a table. Date Time Code 1/1/2003 1700 xbc 1/1/2003 1800 xbc 1/1/2003 1800 xbc 2/4/2004 1650 abc 2/4/2004 1700 abc The problem is I need a...
2
1941
by: glenn | last post by:
Hi folks, I guess this question has to do with formatting dates. Seems like it should be a no brainer but have spent too much time hunting so I am posting the forum. I have a function that...
5
3766
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
12
5525
by: colincolehour | last post by:
I am new to Python and am working on my first program. I am trying to compare a date I found on a website to todays date. The problem I have is the website only shows 3 letter month name and the...
46
2483
by: Bruce W. Darby | last post by:
This will be my very first VB.Net application and it's pretty simple. But I've got a snag in my syntax somewhere. Was hoping that someone could point me in the right direction. The history: My...
4
1662
by: trint | last post by:
I need to get the time from NOW and get how many milleseconds until 1:00am for my countdown timer please. Any help is appreciated. Thanks, Trint
6
1699
by: Designing Solutions WD | last post by:
I have the following table. GO /****** Object: Table . Script Date: 05/01/2007 10:42:31 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO
0
7264
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
7166
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
7386
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,...
1
5094
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3236
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...
0
3226
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1601
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 ...
0
459
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...

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.