DateTime problem for aspx page

Posted on 2003-03-23
Medium Priority
Last Modified: 2010-04-15

I am trying to get the current date and the current time as two *separate* entities.

I have tried

DateTime d = DateTime.Now;                      

But this still insists on giving the time (00.00.00) after the date (shown correctly).

How can I get the date and time alone ?

Cheers in advance.
Question by:mrwad99
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 23

Expert Comment

ID: 8190815
Try this..

string strDate = d.ToString("d",DateTimeFormatInfo.InvariantInfo);
string strtime = d.ToString("T",DateTimeFormatInfo.InvariantInfo);
LVL 10

Expert Comment

ID: 8195134

string strDate=d.ToShortDateString();
string strTime=d.ToShortTimeString();
LVL 19

Author Comment

ID: 8195696
OK they both work but give the date in MM/DD/YY format; how can I get it in DD/MM/YY format ?

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 10

Accepted Solution

smegghead earned 80 total points
ID: 8195768
change your locale settings to use this format (international setting in control panel) or use a specific format string

string strDate=d.ToString("dd/MM/yyyy");
LVL 19

Author Comment

ID: 8195806
Brilliant.  Thanks a lot.

Also thanks to naveenkohli for the an equally good first answer.
LVL 10

Expert Comment

ID: 8195853

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question