473,804 Members | 2,194 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing a DateTime format --- please help!

Hi,

Hope that you can help me with this. I'm calling DateTime.Now and
storing in a DateTime container. I see that the pattern format is: m/
dd/yyyy

I need it to be in the format: yyyy-MM-dd HH:MM:SS as type DateTime
but I don't know how to do this! Can anyone help me please? Any
comments/advice/suggestions/code-sampels much appreciate.

Cheers,
Al.
Feb 27 '08 #1
2 1665
As others have said, if you are converting to a string representation of the
date, use ToString(). There is a whole heap to think about here though
including globalisation (if the application is not for a particular
local-region-only solution).

I have put together an article on DateTime manipulation that includes
information on standard formats and "Picture" formatting at
http://www.blackwasp.co.uk/CSharpDateManipulation.aspx.

--

BlackWasp
www.blackwasp.co.uk
<al*****@altavi sta.comwrote in message
news:1e******** *************** ***********@u72 g2000hsf.google groups.com...
Hi,

Hope that you can help me with this. I'm calling DateTime.Now and
storing in a DateTime container. I see that the pattern format is: m/
dd/yyyy

I need it to be in the format: yyyy-MM-dd HH:MM:SS as type DateTime
but I don't know how to do this! Can anyone help me please? Any
comments/advice/suggestions/code-sampels much appreciate.

Cheers,
Al.
Feb 28 '08 #2
On Wed, 27 Feb 2008 09:42:42 -0800 (PST), al*****@altavis ta.com wrote:
Hi,

Hope that you can help me with this. I'm calling DateTime.Now and
storing in a DateTime container. I see that the pattern format is: m/
dd/yyyy

I need it to be in the format: yyyy-MM-dd HH:MM:SS as type DateTime
but I don't know how to do this! Can anyone help me please? Any
comments/advice/suggestions/code-sampels much appreciate.

Cheers,
Al.
As has been suggested, one way is to use ToString() with the appropriate
format specifiers.

--
http://www.thinkersroom.com/bytes
Feb 28 '08 #3

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

Similar topics

16
10517
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am using C# eg. - String variable "strMyDate" holds the value "1/1/2005 12:00:00 AM" from the database. - I do not care about the time portion, I only want "1/1/2005" for display.
15
14290
by: Fritz Switzer | last post by:
I'd like to have a string assigned the value of a DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" format. For example: DateTime.Now.AddMinutes(30) returns "00:30" DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"
7
7494
by: .Net Sports | last post by:
Before processing my data in a datagrid, I need to parse the day of the week (which will be my 'rqsday' variable) from a string that comes over on a querystring: string rqs = Request.QueryString; string rqsday; rqsday = (System.String.Format("{0:dddd}",rqs)) ;
38
807
by: nobody | last post by:
I know that given a FormatString and a DateTime you can use DateTime.ToString(...) to convert the DateTime to a String. My question is how can you turn that around? Given a String and a FormatString, how can you convert the String back to a DateTime? DateTime.Parse(...) doesn't use the FormatString. Now admitedly, if the format string is just "MM", it can't be done. But if the format string is "yyyyMMdd", or "ddMMMyyyy hhmmsst", it...
20
35644
by: andreas | last post by:
When I copy a vb.net project using date formats from one PC with a windows date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I get errors. How can I change for a while in the project the date format in vb.code ( not in Windows) and how can I find out which date format the PC Windows is using. Thanks for any response
11
2181
by: Axel Dahmen | last post by:
Hi, I'm working in a team developing an international website. When I set the page's CultureInfo to Hungarian (hu-HU) then the RangeValidator doesn't seem to be able to parse a TextBox's date value (Exception message see below) correctly. The TextBox's value is coming from the DateTime.Now.ToShortDateString() function, so it's an original .NET value.
6
4131
by: B.N.Prabhu | last post by:
Hi, I am having a DataTable which one column is in string format now i want to change that one to DataTime. I don't know whether its in datetime format or not i have to check if it is in DateTime Format some times it may in normal string not a DateTime. If it is in any one of the DateTime format then i have to change it as a Specfic format as "21-03-2005 11:34" using C#.Net. If its not in DateTime format then i should give a message.
5
5148
by: js | last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss". I need to parse the text using System.DateTime.Parse() function with custom format. I got an error using the following code. Could someone help me with the customization? Thanks. String was not recognized as a valid DateTime. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s, IFormatProvider...
6
1416
by: =?Utf-8?B?ZGVlcGFr?= | last post by:
Hi All, How to convert the 1st format of string to 2nd one in vb.net 1st(datetype string) : "2/12/2008 6:00:00 PM" 2nd(datatype string): "2008-2-12T17:00:00" note: in 2nd string ,the T is just a alpahbet Thanks,
0
9715
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
10603
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
9176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6869
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
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...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
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
3
3003
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.