Date and time stamp from current date & time

Posted on 2006-04-24
Last Modified: 2012-06-27
I am trying to apply a date and time stamp showing date and time in the format:  yyyy-mm-dd hh:MM:ss  I want to be able to easily display rows in chronological order.  Could someone provide the following:

1)  Code snippet for retrieving the info from system date
2   defning and storing the column in sql server
Question by:garyinmiami2003
    LVL 85

    Accepted Solution

    (1) Use the ToString() method of the DateTime() class:

            Dim strDate As String = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")

        Notice that the Month is uppercase "MM", while the Minutes are lowercase "mm".  Also, I used uppercase "HH" for the hours, which gives you a 24 hour format resulting in values between 00 and 23.  If you want a twelve hour format then use lowercase "hh".  To add the AM/PM on the end, add "tt":

            Dim strDate As String = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt")

    (2) I have no idea...   =(
    LVL 4

    Assisted Solution


    for 1) use DateTime.Now.ToString(("yyyy-MM-dd HH:mm:ss")

    for 2) when defining a column as datetime, sql server stores the data with time values..

    LVL 2

    Assisted Solution

    for 2) Make sure you specify the sort order in your query string..."...order by datecolumn"

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now