Current Date and Time in Classic ASP: Date, Time and Now

Use Date for today's date, Time for the current time and Now for both. All three read the web server's clock, not the visitor's clock.

<%
Response.Write "Date: " & Date & "<br>"
Response.Write "Time: " & Time & "<br>"
Response.Write "Date and time: " & Now
%>

Save the example as a .asp file and run it on IIS with Classic ASP enabled. The displayed values change at runtime according to the server clock and its regional formatting settings. You do not need to install a third-party library.

Which function should I use?
  • Date: current server date for date-based comparisons or display.
  • Time: current server time for time-of-day display.
  • Now: date and time together, suitable for timestamps in server-local time.
On this page — Show page sectionsHide page sections

Date(), Time() and Now(): comparison

VBScript functionReturnsUse case
DateCurrent server dateToday's date, deadlines and calendar views
TimeCurrent server timeShow the time or test the hour
NowCurrent server date and timeRecord when a server-side action occurred

They return VBScript date/time values, not preformatted strings. Their appearance when written to a page depends on locale settings. Use date formatting when a specific display is required.

Get today's date with Date

The Date function retrieves the date from the server's operating system. There is no argument to pass. The date value represents the current calendar day in the server's time zone.

<%
Option Explicit
Dim todayValue
todayValue = Date
Response.Write "Today is " & todayValue
%>

The output could appear as 12/11/2026 or 11/12/2026 depending on the server locale. Do not depend on such an ambiguous string representation when interpreting dates.

Print a readable long date

<%
Response.Write FormatDateTime(Date, vbLongDate)
%>

vbLongDate uses the server's locale-specific long date pattern, which may include the weekday and month name. For custom numeric layouts, see the consistent numeric format example below.

Get only the current time with Time

Time returns the server's current clock time. It is useful for time-only displays and time-of-day checks. The text shown by Response.Write can include seconds and AM/PM depending on regional settings.

<%
Option Explicit
Dim currentTime
currentTime = Time
Response.Write "Current server time: " & currentTime
%>

For a more predictable human-readable display, use FormatDateTime(Time, vbLongTime) or vbShortTime. For extracting the hour, minute or second as numbers, use Hour(), Minute() and Second().

Get the current date and time with Now

Now combines the server's current date and time in one VBScript date value. This is useful for showing when a report was generated or when an action happened, as long as you understand the server's time zone.

<%
Option Explicit
Dim generatedAt
generatedAt = Now
Response.Write "Report generated at: " & generatedAt
%>

The date and time shown here are evaluated while the page executes. If a process spans a date boundary, Date and Time called separately can technically describe different moments; capture Now once when both components must refer to the same instant.

Capture one date/time value and reuse it

<%
Dim capturedAt
capturedAt = Now
Response.Write "Date: " & DateValue(capturedAt) & "<br>"
Response.Write "Time: " & TimeValue(capturedAt) & "<br>"
Response.Write "Full value: " & capturedAt
%>

DateValue() extracts the date and TimeValue() extracts the time from the same captured value. This is helpful when building a consistent report header or page footer.

Extract year, month, day, hour, minute and second

VBScript supplies component functions that return numbers from the date/time value. These work with Now or any valid VBScript Date. For more interval codes, see DatePart() in Classic ASP.

<%
Option Explicit
Dim stamp
stamp = Now
Response.Write "Year: " & Year(stamp) & "<br>"
Response.Write "Month: " & Month(stamp) & "<br>"
Response.Write "Day: " & Day(stamp) & "<br>"
Response.Write "Hour: " & Hour(stamp) & "<br>"
Response.Write "Minute: " & Minute(stamp) & "<br>"
Response.Write "Second: " & Second(stamp)
%>

Month() returns 1 through 12. Hour() returns 0 through 23. These numeric components are easier to compare and manipulate than a formatted date string.

Get the weekday name and current month name

<%
Dim todayValue
todayValue = Date
Response.Write "Day: " & WeekdayName(Weekday(todayValue)) & "<br>"
Response.Write "Month: " & MonthName(Month(todayValue))
%>

Weekday and month names use regional settings. See Weekday() / WeekdayName() and MonthName() for more examples and their optional arguments.

Format the date and time with FormatDateTime()

FormatDateTime(value, format) converts a VBScript Date into a locale-aware display string. This is appropriate for pages seen by people, but its output format can vary between servers and regional settings.

<%
Dim stamp
stamp = Now
Response.Write FormatDateTime(stamp, vbGeneralDate) & "<br>"
Response.Write FormatDateTime(stamp, vbLongDate) & "<br>"
Response.Write FormatDateTime(stamp, vbShortDate) & "<br>"
Response.Write FormatDateTime(stamp, vbLongTime) & "<br>"
Response.Write FormatDateTime(stamp, vbShortTime)
%>
ConstantValueDescription
vbGeneralDate0General date and/or time
vbLongDate1Long, locale-dependent date
vbShortDate2Short, locale-dependent date
vbLongTime3Long, locale-dependent time
vbShortTime4Short time, typically hours and minutes

Important: formatting a value changes only the displayed string. It does not change the underlying server time. For additional examples, see FormatDateTime() and date formatting.

Change regional date formatting with SetLocale()

SetLocale() changes the locale used by VBScript for region-sensitive operations such as formatting dates. The function returns the previous locale identifier (LCID), which should be saved if you plan to change it temporarily.

<%
Option Explicit
Dim previousLocale, ignored, stamp
stamp = Now
previousLocale = SetLocale(2057)  ' English (United Kingdom)
Response.Write "UK: " & FormatDateTime(stamp, vbLongDate) & "<br>"
ignored = SetLocale(previousLocale)  ' Restore previous locale
%>

2057 is the LCID for English (United Kingdom). The code saves the original value and restores it after the example. Do not set the locale globally on a shared page unless the rest of that page is meant to use it.

Locale is not a time-zone conversion. SetLocale(2057) affects date text and parsing conventions; it does not change the server clock from one time zone to another. A visitor in a different country can still see the server's date and time.

Build a consistent YYYY-MM-DD and HH:MM:SS display

When you need a predictable order of numeric components, compose the display using Year(), Month(), Day(), Hour(), Minute() and Second(). Right("0" & value, 2) adds a leading zero to single-digit components.

<%
Option Explicit
Dim stamp, yyyyMmDd, hhMmSs
stamp = Now
yyyyMmDd = Year(stamp) & "-" & Right("0" & Month(stamp), 2) & "-" & Right("0" & Day(stamp), 2)
hhMmSs = Right("0" & Hour(stamp), 2) & ":" & Right("0" & Minute(stamp), 2) & ":" & Right("0" & Second(stamp), 2)
Response.Write yyyyMmDd & " " & hhMmSs
%>

Example format: 2026-11-12 09:05:07. This string is server-local time, not necessarily UTC. It is useful for displaying stable numeric dates; when saving timestamps to a database, prefer properly typed date/time columns and an explicit time-zone policy. See Classic ASP and SQL Server date/time and SQL Server default dates.

This example assumes the application uses the usual Gregorian calendar. If the calendar or locale settings are changed, test component-based formatting under those settings.

Practical uses of current date and time

Show a greeting based on the server hour

A simple time-of-day greeting is useful on an internal dashboard. The following checks the server's current hour. If you intend the message to follow a visitor's local morning or evening, use the visitor's time zone instead.

<%
Dim currentHour, greeting
currentHour = Hour(Now)
If currentHour < 12 Then
    greeting = "Good morning"
ElseIf currentHour < 17 Then
    greeting = "Good afternoon"
Else
    greeting = "Good evening"
End If
Response.Write greeting
%>

Calculate tomorrow and a date seven days ahead

Use DateAdd() to add time intervals without manually accounting for month ends and leap years. A positive number moves forward; a negative number moves backward.

<%
Response.Write "Tomorrow: " & DateAdd("d", 1, Date) & "<br>"
Response.Write "Seven days later: " & DateAdd("d", 7, Date) & "<br>"
Response.Write "Yesterday: " & DateAdd("d", -1, Date)
%>

Show the number of days until a future date

DateDiff("d", ...) counts day interval boundaries. If you want a whole-day countdown based on calendar dates rather than hours remaining, compare date-only values.

<%
Dim targetDate, daysRemaining
targetDate = DateSerial(2027, 1, 1)
daysRemaining = DateDiff("d", Date, targetDate)
Response.Write "Calendar days to target: " & daysRemaining
%>

The value can become negative after the target date. For further details about interval-boundary counting, see DateDiff() and DateSerial().

Find the last date of the current month

<%
Dim endOfMonth
endOfMonth = DateSerial(Year(Date), Month(Date) + 1, 0)
Response.Write FormatDateTime(endOfMonth, vbLongDate)
%>

DateSerial() can normalize an out-of-range day value. Day 0 of the next month is the last day of the current month, so this works for February and other month lengths too. The server's calendar settings still matter.

Complete sample: a server-generated date and time panel

This complete .asp example prints a date and time, includes a formatted date, and shows a numeric timestamp. It uses only built-in Classic ASP and VBScript functions; save it as server-clock.asp on a Classic ASP-enabled IIS site.

<%@ Language="VBScript" %>
<% Option Explicit %>
<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Server Date and Time</title></head>
<body>
  <h1>Server Date and Time</h1>
<%
Dim stamp, dateLabel, timeLabel
stamp = Now
dateLabel = FormatDateTime(stamp, vbLongDate)
timeLabel = FormatDateTime(stamp, vbLongTime)
Response.Write "<p>Date: " & Server.HTMLEncode(dateLabel) & "</p>"
Response.Write "<p>Time: " & Server.HTMLEncode(timeLabel) & "</p>"
Response.Write "<p>Year: " & Year(stamp) & "</p>"
%>
</body>
</html>

Server.HTMLEncode() is included when writing formatted text into HTML. The date/time values come from built-in functions here, but encoding output is a good habit when templates later add variable or user-provided text.

Server date/time versus the visitor's local date/time

Classic ASP does not automatically infer a browser visitor's time zone. If the server is in one region and the visitor is in another, the two local times can differ, and near midnight they may show different calendar dates.

A browser can show the visitor's local clock using JavaScript. The following is a client-side example, not a Classic ASP time-zone conversion:

<p id="visitor-time">Loading local time...</p>
<script>
  const target = document.getElementById("visitor-time");
  target.textContent = "Your local time: " + new Date().toLocaleString();
</script>

For storage or cross-region calculations, define a clear time-zone convention (commonly UTC) and perform an explicit, reliable conversion with tools that know time-zone offsets and daylight-saving rules. A display format such as YYYY-MM-DD HH:MM:SS does not, by itself, record the time zone.

Hosting note: HTML examples on this .php tutorial page only display ASP code. They do not execute VBScript. Copy the example into an .asp file on a Windows IIS server with Classic ASP enabled to see the dynamic output.

Common errors and troubleshooting

IssueCause and suggested fix
Wrong date or hourVerify the IIS server clock, time zone and daylight-saving configuration; SetLocale() does not alter the clock.
Day/month appear swappedShort date displays are locale-dependent. Use FormatDateTime() for the intended locale or construct an unambiguous numeric string.
Now shows an unexpected time zoneNow reads the server. Use a deliberate server-to-visitor conversion if local visitor time is needed.
Type mismatch while parsing text as a dateBefore calling CDate() on user-supplied text, check IsDate() and account for locale-sensitive parsing. Use validated separate day, month and year inputs when appropriate.
The code is shown as text instead of runningMake sure the executing file ends in .asp, has valid <% ... %> delimiters, and runs through an IIS server with Classic ASP enabled.
Code works locally but looks different on the serverConfirm the server locale and calendar settings. For portable data, keep the stored date value separate from its display format.
Times disagree between repeated callsCapture Now once and reuse the captured value throughout the response.

Frequently asked questions

What is the difference between Date and Now in Classic ASP?

Date gives the current server date. Now gives both the current server date and time. Choose Date for calendar-day comparisons; choose Now when the time also matters.

How do I get only the time?

Use Time, or extract TimeValue(Now) from a previously captured timestamp. Hour(), Minute() and Second() return individual numeric parts.

Can I use Date() and Now() with parentheses?

These built-in zero-argument VBScript functions are commonly written as Date, Time and Now. The examples here use that conventional form, which is clear and works in Classic ASP VBScript.

How can I show today's date as YYYY-MM-DD?

Combine Year(Date), zero-padded Month(Date) and zero-padded Day(Date), as shown in the numeric-format example. This avoids relying on the display order used by FormatDateTime().

Does SetLocale change the time zone?

No. SetLocale() changes locale-dependent formatting and parsing, not the server's actual time zone. Use time-zone-aware conversion logic when a visitor-specific clock is needed.

Does Classic ASP automatically use the visitor's local date and time?

No. The built-in functions run on the server. The visitor's browser can supply a local date/time value via JavaScript if needed, but applications must decide how to validate, convert and store it.

What happens if the server switches to daylight saving time?

The server's local clock can change its UTC offset. Avoid interpreting a local timestamp without any time-zone context as a unique instant, especially when dealing with logs or systems in different regions.

Which should I use for a deadline or expiry date?

Use DateAdd() to calculate offsets and DateDiff() to compare intervals. Decide whether the deadline is based on an absolute timestamp or the user's local calendar day before comparing.

These related Classic ASP tutorials explain the individual functions in more detail.

TutorialWhat you can learn
FormatDateTime()How date and time are displayed in regional formats
DateAdd()Add or subtract days, months, years or time intervals
DateDiff()Calculate differences between dates
DatePart()Extract year, month, day, week, quarter or hour
MonthName()Get localized month names from month numbers
Weekday() and WeekdayName()Identify days of the week
DateSerial()Create date values from year, month and day
IsDate()Test whether values can be interpreted as dates
Validate date inputAccept and verify date values entered in forms
ASP and SQL Server date/timeWork with dates in a database-backed ASP application

Official function reference: Microsoft: FormatDateTime function. Microsoft documents the same date/time formatting constants used in these VBScript examples.

Back to top ↑


ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer