Simple Code for Getting Current Date and Time

Updated JJCollins 0 Tallied Votes 2K Views Share

Just a quick snippet for beginners

Public Shared Function getCurrentDateTimeString() As String ' Returns current date and time in this format: "yyyyMMddHHmmssff"         Dim rightNow As DateTime = DateTime.Now         Dim strCurrentDateTimeString As String         strCurrentDateTimeString = rightNow.ToString("yyyyMMddHHmmssff")         Return (strCurrentDateTimeString)     End FunctionPublic Shared Function getCurrentDateTimeString() As String ' Returns current date and time in this format: "yyyyMMddHHmmssff"

        Dim rightNow As DateTime = DateTime.Now

        Dim strCurrentDateTimeString As String

        strCurrentDateTimeString = rightNow.ToString("yyyyMMddHHmmssff")

        Return (strCurrentDateTimeString)

    End Function
kvprajapati 1,826 Posting Genius Team Colleague
Momerath 1,327 Nearly a Senior Poster Featured Poster

Why go through all the variable manipulation:

Public Shared Function getCurrentDateTimeString() As String ' Returns current date and time in this format: "yyyyMMddHHmmssff"
    return DateTime.Now.ToString("yyyyMMddHHmmssff"
End Function
JJCollins 0 Junior Poster in Training

I like to do things the long way for beginners, the code is simple but there is more of it, just feel you'll learn more about the language, syntax etc from 6 lines of code rather than 3, personal preference i guess :)

- Jordan

bossie09 0 Light Poster

Any one here can help me with a programming assignment....... C, C++ or Java language, anyone, WE can negotiate a price.

JJCollins 0 Junior Poster in Training

This is the wrong forum for C / C++ / Java my friend, a post in the appropriate forum would be better for you

- Jordan

Wel Da gr8 0 Newbie Poster

Hi,

I need a code to show only the previous month date i.e. the program executes this month but must show last months date or just a month. So there's a message that says "attached is the monthly report", instead of saying 'monthly' report, it must print the last month's name 'month' e.g. 'Feb', 'Mar' etc ...

Thnx
W.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.