473,396 Members | 2,090 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,396 software developers and data experts.

Format string as short date

using c#3.5, how do I take a string which contains a data, and format it as
a short data format like this:

"2/5/2008 1:17:11 AM"

and format to:

"02/05/2008"

Thanks.

--
mo*******@newsgroup.nospam
Feb 11 '08 #1
3 47857
On Mon, 11 Feb 2008 09:57:26 -0800, moondaddy <mo*******@newsgroup.nospam>
wrote:
using c#3.5, how do I take a string which contains a data, and format it
as
a short data format like this:

"2/5/2008 1:17:11 AM"

and format to:

"02/05/2008"
Well, one way would be to use the DateTime.TryParse() method to convert
the string to a DateTime object, and then use the
DateTime.ToShortDateString() to reformat the data into the the string you
want.

Pete
Feb 11 '08 #2
MoonDaddy,

First check the globalization settings are US then just

\\\

var date = DateTime.Parse("5/2/2008 1:17:11").ToShortDateString();

///

I have done it in my globalisation settings.

Cor
Feb 11 '08 #3
Hi,

You have to convert the string to DateTime and then use
DateTime.ToShortDateString();

Take a lookat DateTime.TryParse or Convert.ToDateTime

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"moondaddy" <mo*******@newsgroup.nospamwrote in message
news:eH***************@TK2MSFTNGP06.phx.gbl...
using c#3.5, how do I take a string which contains a data, and format it
as a short data format like this:

"2/5/2008 1:17:11 AM"

and format to:

"02/05/2008"

Thanks.

--
mo*******@newsgroup.nospam

Feb 11 '08 #4

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

Similar topics

1
by: Laurence Neville | last post by:
This is regarding a change in the Short Date format under Hebrew Regional Settings, that has caused huge problems in our ASP web application. The change appears to have been introduced sometime...
4
by: Jo | last post by:
Is there anyway we can know using JavaScript the Short Date Format used in the Control Panel -> Regional and Language Settings? I know the using the combinations of following we can get the...
2
by: ABC | last post by:
Hi, All Which function return the desktop long and short date formats? Thanks
7
by: Edward Mitchell | last post by:
I have a number of DateTimePicker controls, some set to dates, some set to a format of Time. The controls are all embedded in dialogs. I created the controls by dragging the DateTime picker from...
3
by: MattB | last post by:
I've hit a snag with an application I wrote because of the differing date formats in different countries. It's a set of pages that make calls to a COM object that I have wrapped in a web...
5
by: Ellis Yu | last post by:
Dear All I want to read the short date format pattern from the regional setting. I write a code as follow: 'Diff. machine may has different country setting, so I use blank here Dim a as new...
6
by: ABC | last post by:
Is there any function return the short date format on the regional and Language Options under control panel?
2
by: savigliano | last post by:
hello, i am doing a date comparation and i have reallize that the data i have in my database (general date format) it is causing me problems, and because i donīt need the time data i would like to...
6
by: theinvisibleGhost | last post by:
Is there a method of determining which format the short date format is stored in for the current user on the machine using .NET? If it is not in UK format I ideally need to be able to set it to...
1
by: Doug | last post by:
Hi, I created a short date field. The format is dd/mm/yyyy when displayed. The input mask is set to 99/99/00;0 (default, I didn't type anything). If I edit an existing date, say change...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
0
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...
0
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...
0
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...

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.