Formatting ASP date yyyy-mm-dd hh:mm:ss

Posted on 2009-04-28
Last Modified: 2012-05-06
I need my date formatted like:
yyyy-mm-dd hh:mm:ss
Is there a function for this?

Question by:JuniorBee
    LVL 33

    Expert Comment

    by:Todd Gerbert
    Yes, check documentation for the .ToString method of the DateTime object.

    DateTime dt = DateTime.Now;
    Response.Write(dt.ToString("yyyy-MM-dd HH:mm:ss"));

    Dim dt As DateTime = DateTime.Now
    Response.Write(dt.ToString("yyyy-MM-dd HH:mm:ss"))
    LVL 33

    Accepted Solution

    Sorry...assumed ASP.Net.

    Using VBScript with older ASP you would need to use the Year(), Day(), Month(), etc. functions to get the pieces of a Time variable.

    Dim currentTime

    currentTime = Now
    Response.Write Year(currentTime) & "-" & Month(currenTime) & "-" & Day(currentTime) . . . etc.

    Expert Comment

    How will the date and time be presented to the function.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
    This video discusses moving either the default database or any database to a new volume.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now