473,486 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DateTime /File question


Hello,
I am trying to add Date and Current time to a name of a log file. I
tried doing this:

string logDateExtention = DateTime.Now.ToShortDateString().ToString() +
DateTime.Now.ToShortTimeString().ToString();

string logName = Data.Name + Data.ProductName + logDateExtention;

And this throws exception during the debug that the name is not legal
probably because of the ":" or "/" . Which format of date will work for
this purpose?

Thanks!
*** Sent via Developersdex http://www.developersdex.com ***
Mar 24 '08 #1
2 1637
On Mon, 24 Mar 2008 05:36:18 -0700, csharpula csharp <cs*******@yahoo.com>
wrote:
>
Hello,
I am trying to add Date and Current time to a name of a log file. I
tried doing this:

string logDateExtention = DateTime.Now.ToShortDateString().ToString() +
DateTime.Now.ToShortTimeString().ToString();

string logName = Data.Name + Data.ProductName + logDateExtention;

And this throws exception during the debug that the name is not legal
probably because of the ":" or "/" . Which format of date will work for
this purpose?
My suggestion would be someting like YYYYMMDD (maybe separate them using
underlines) because that also sorts well.

Use e.g.

logDateExtension = DateTime.Now.ToString("yyyyMMdd");

or

logDateExtension = DateTime.Now.ToString("yyyy_MM_dd");

Regards,
Gilles.

Mar 24 '08 #2
You may want to avoid using yyyymmdd and the like if your application needs
to use the user's preference / locale for formatting. In which case, use
"g" as the format string to combine short date and short time.

Check out my article on DateTime manipulation, which explains the various
formatting options for more info.

http://www.blackwasp.co.uk/CSharpDateManipulation.aspx

--

BlackWasp
www.blackwasp.co.uk
"csharpula csharp" <cs*******@yahoo.comwrote in message
news:ub**************@TK2MSFTNGP05.phx.gbl...
>
Hello,
I am trying to add Date and Current time to a name of a log file. I
tried doing this:

string logDateExtention = DateTime.Now.ToShortDateString().ToString() +
DateTime.Now.ToShortTimeString().ToString();

string logName = Data.Name + Data.ProductName + logDateExtention;

And this throws exception during the debug that the name is not legal
probably because of the ":" or "/" . Which format of date will work for
this purpose?

Thanks!
*** Sent via Developersdex http://www.developersdex.com ***
Mar 24 '08 #3

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

Similar topics

3
2954
by: Grant Edwards | last post by:
Is it true that a datetime object can convert itself into a string, but not the other way around? IOW, there's no simple way to take the output from str(d) and turn it back into d? So, I tried...
4
442
by: Nader Emami | last post by:
L.S., It is very simple question: Why doesn't work the next statments? import datetime today = datetime.date.today() and I get the next error:
4
9535
by: Viktor Jevdokimov | last post by:
Hello, I've got an XML file saved from DataSet. One table has datetime column (datatype - xs:dateTime). XML file fragment for example: <Root>...
3
4224
by: Andrew S. Giles | last post by:
Hello, I am importing a flat text file, and putting it into a datagrid for display on a form. Currently the users have their dates and times seperated. I have two fields, therefore in the...
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...
9
4895
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
8
2471
by: Mika M | last post by:
Is there better way to convert integer type date into DateTime type date as doing like code below? Dim intDate As Integer = 20051019 Dim dte As DateTime = New DateTime( _...
1
3758
by: ye juan | last post by:
Hi, all I have some questions to ask: 1. How can I add a standard module named "datetime" in Jython when the error happens :"Traceback (innermost last): File "C:\python\test.py", line 3, in...
5
5438
by: mroeloffs | last post by:
Hi I have a time in microseconds, for example 0x8C905CBA7F84AF4. I want this to a normal view in hh:mm:ss DD:MM:YYYY. I tried with datetime, but it only takes a max of 1000000 microseconds is there...
0
7100
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
6964
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
7175
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
5434
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,...
0
4559
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
3070
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
1378
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 ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
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.