Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Part help needed. 2

Status
Not open for further replies.

jazzz

Technical User
Feb 17, 2000
433
0
0
US
I would like to place the month and year into a web page using vbscript on an ASP Page. Since datePart will allow me to retrieve the month and year I would like to show the following on my web page October 2003 for example.

So do I need to set Contants for the months such as
Const January = 1
Const February = 2
Const March = 3
etc.

varThisMonth = DatePart("m", Date) 'this returns 10
varThisYear = DatePart("y", Date) 'this returns 2003

Now how do I put this together to show me October, 2003?

Life's a journey enjoy the ride...

jazzz
 
Use the Format Date Function.

FormatDateTime Function
Returns an expression formatted as a date or time.

FormatDateTime(Date[, NamedFormat])

Arguments
Date

Required. Date expression to be formatted.

NamedFormat

Optional. Numeric value that indicates the date/time format used. If omitted, vbGeneralDate is used.

Settings
The NamedFormat argument has the following settings:

Constant Value Description
vbGeneralDate 0 Display a date and/or time. If there is a date part, display it as a short date. If there is a time part, display it as a long time. If present, both parts are displayed.
vbLongDate 1 Display a date using the long date format specified in your computer's regional settings.
vbShortDate 2 Display a date using the short date format specified in your computer's regional settings.
vbLongTime 3 Display a time using the time format specified in your computer's regional settings.
vbShortTime 4 Display a time using the 24-hour format (hh:mm).


Remarks
The following example uses the FormatDateTime function to format the expression as a long date and assign it to MyDateTime:

Function GetCurrentDate
' FormatDateTime formats Date in long date.
GetCurrentDate = FormatDateTime(Date, 1)
End Function


MrGreed

"did you just say Minkey?, yes that's what I said."
 
Thank you Mr. Greed however, I am new to vbscript in ASP so do I create the Function in the head section? Do I prefix it with
<%
Function GetCurrentDate
' FormatDateTime formats Date in long date.
GetCurrentDate = FormatDateTime(Date, 1)
End Function
%>

Then to place it on my page do I use
<% Response.write MyDateTime =GetCurrentDate %>

Sorry for being so dumb but once I get one of these figured out the rest will be easy.

Thank you.

Life's a journey enjoy the ride...

jazzz
 
Kind of Simple but it works great
Paste into ASP Page:
<%
td = now()

select case month(td)
Case 1
md =&quot;January&quot;
Case 2
md =&quot;February&quot;
Case 3
md =&quot;March&quot;
Case 4
md =&quot;April&quot;
Case 5
md =&quot;May&quot;
Case 6
md =&quot;June&quot;
Case 7
md =&quot;July&quot;
Case 8
md =&quot;August&quot;
Case 9
md =&quot;September&quot;
Case 10
md =&quot;October&quot;
Case 11
md =&quot;November&quot;
Case 12
md =&quot;December&quot;
case else
md =&quot;Octobuary&quot;

end select

Response.write(md & &quot; &quot; & year(td))
%>
 
Thanks guys got it figured out.

Life's a journey enjoy the ride...

jazzz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top