|
Use Format Function
Ex : format(now.day ,"00")
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
.... or now.Days.ToString("D2")
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
small correction
instead of "Days" put "Day"
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
Use a format string to get the parts of the date formatted the way that you want.
Examples:
Dim fullDate = theDate.ToString("yyyy-MM-dd")
Dim year = theDate.ToString("yyyy")
Dim month = theDate.ToString("MM")
Dim day = theDate.ToString("dd")
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks to everyone for the quick reply!
|
|
|
|
|
You can use the following function:
#Region "Function GetDate - returns date / time according to format"
Public Function GetDate(ByVal MyFormat As String, Optional ByVal dt As Date = Nothing) As String
Try
If dt = Nothing Then
Return Now.ToString(MyFormat, DateTimeFormatInfo.InvariantInfo)
Else
Return dt.ToString(MyFormat, DateTimeFormatInfo.InvariantInfo)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "GetDate", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Return ""
' MyFormat can be
' * d :08/17/2000
' * D :Thursday, August 17, 2000
' * f :Thursday, August 17, 2000 16:32
' * F :Thursday, August 17, 2000 16:32:32
' * g :08/17/2000 16:32
' * G :08/17/2000 16:32:32
' * m :August 17
' * r :Thu, 17 Aug 2000 23:32:32 GMT
' * s :2000-08-17T16:32:32
' * t :16:32
' * T :16:32:32
' * u :2000-08-17 23:32:32Z
' * U :Thursday, August 17, 2000 23:32:32
' * y :August, 2000
' * dddd, MMMM dd yyyy :Thursday, August 17 2000
' * ddd, MMM d "'"yy :Thu, Aug 17 '00
' * dddd, MMMM dd :Thursday, August 17
' * M/yy :8/00
' * dd-MM-yy :17-08-00
' *dd/MM/yyyy : 17/08/2000
End Function
#End Region
Comment:
You can improve and add another overloaded function that will get as parameter an enum parameter (containing the different formats)
Shay Noy
|
|
|
|
|
Thanks again but i got it working using the following code to timestamp a file that I have processed:
File.Move(fileToMove, ConfigurationManager.AppSettings("NewPath").ToString() _
& Path.GetFileNameWithoutExtension(fileToMove) _
& " " & System.DateTime.Now.Day.ToString("D2") _
& System.DateTime.Now.Month.ToString("D2") _
& System.DateTime.Now.Year.ToString("D4") _
& "_" & System.DateTime.Now.Hour.ToString("D2") _
& System.DateTime.Now.Minute.ToString("D2") _
& System.DateTime.Now.Second.ToString("D2") _
& System.DateTime.Now.Millisecond.ToString("D3") _
& Path.GetExtension(fileToMove).ToString())
|
|
|
|
|
Hi,
this is not OK, you should call DateTime.Now only once, store it in a variable,
and use it over and over; the way you do it, you may get inconsistent information
(imagine what happens when the time goes from 01:59:59 to 02:00:00 WHILE executing
your very long statement!).
Furthermore, you could do it with the DateTime.ToString() method itself, as Guffa already
told you. That one even accepts some unrecognized characters in its format specifier,
so you could try DateTime.Now.ToString("yyyMMdd_HHmmssfff")
Note that I have put the year first, so alphabetical and chronological order is the same thing.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
One more remark,
if the file generation code is in a loop, you may end up with duplicate filenames:
the milliseconds in DateTime.Now don't increment by one; they typically
get increased by 10, 16, or even 55 depending on your hardware and operating system.
If you want to know more about this, you may want to read my timers article.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Thanks for the pointers. Wouldn't have even though of that being a problem!
|
|
|
|
|
hi im new in ADO.NET
i have an error when i test the connection. says: theres no error message for this ....!!!
ive not installed sql server.
|
|
|
|
|
Member 4262317 wrote: i have an error when i test the connection. says: theres no error message for this ....!!!
ive not installed sql server.
You need to get some beginner level book.
|
|
|
|
|
Member 4262317 wrote: ive not installed sql server.
Wow - gotta love when the question tells me that you already must know what the problem is.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
could you provide more info.... whats you code like?
thanks
Anoop
|
|
|
|
|
Anoop Brijmohun wrote: could you provide more info.... whats you code like?
Gosh - you're as bad as the first guy. His code is irrelevant. He doesn't have SQL Server installed.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
What database are you trying to connect to?
|
|
|
|
|
ive got 2007 and 2003 access files
non of them work
when i try to connect using connectionstring i recieve a message box with no message in it!!! and only one ok button!!
|
|
|
|
|
Member 4262317 wrote: and only one ok button!!
Well, one should be enough.
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
Well, here's some info that would have been useful hours ago. Why mention SQL Server at all, if you're not using it ?
What is the connection string you're using ? Can you open the DB using Access on this machine ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
You will need to post the connection string you are using so that we can see if the problem lies there...
|
|
|
|
|
Hai All,
Im creating 2 formula fields in my crystal reports for displaying empname and salary like this,
abc 100
xyz 200
pqr 300
in code behind im passing values to crystal report like this,
vb.net code
j=0
for i=0 to noof emps
rptDocument.DataDefinition.FormulaFields(j).Text = ds.Tables(0).Rows(i).Item(i)
j=j+1
next
It is printing only
pqr 300
ie, It is over writing every time and im getting only last record how to get all emp records at a time..?
Thanks,
Aswath.
Thanks,
Aswath
|
|
|
|
|
Hai,
Any Answer to my problem..........?
Thanks,
Aswath
|
|
|
|
|
To a new (VB.NET 2005) version of my application WDS I would like to add a "direct recording to MP3" feature.
WDS is about talking digital books, please see www.wds-books.com for the old VB6 version.
I looked at several commercial controls (Active Audio Record, Alvas Audio a.o.), but these seem to heavy and I fear distribution problems (dll's, regsrvr).
All I need is a simple micro to mp3-file recording feature, no choice of device or quality is necessary. Just something like:
RecordStart(filename), RecordPause(), RecordResume() and RecordStop().
Has somebody developed anything similar, or give me some hints on where to find info?
Thanks in advance for your kind reaction.
Fred Worms
|
|
|
|
|
There's no mp3 encoding built into .NET, so you need an extra component to do the encoding for you. Then, if you want to do it yourself, you will need to use DirectX to do it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thank you Christian for your quick reply. Vielen Dank.
Extra control: I looked at three of these. Example programs do not work, or work on Vista, crash with XP. I lost lots of time in the past using controls of small firms.
I hoped to get a more detailed reaction from someone experienced in this respect, e.g. from Qualtar, who published an article on a somewhat similar LAME encoder subject.
I would like to address Qualtar directly, however, I have the impression that this is not possible(I know very little about forums).
I do not like at all your attempt to be funny at the end of your reply.
Kind regards,
Fred
Fred Worms
|
|
|
|