ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old June 14th, 2003, 02:00 PM
fmh002 fmh002 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 38 fmh002 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m
Reputation Power: 5
putting a formatted date in a text box

hello

i need to put a date of the following format: 14 June 2003 into a text box. i have seen some samples but i can't get what i want.

i tried the following: <%=FormatDateTime(todaysDate,0) %> and it only rendered 00:00:00

i need help ppl.

thnx in advance,
fmh002

Reply With Quote
  #2  
Old June 14th, 2003, 09:01 PM
spincycler spincycler is offline
&nbsp;
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Brisbane
Posts: 15 spincycler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
here's a great function that'll do the job...

Code:


	<% 
	Function FormatDate( _
	   byVal strDate, _
	   byRef strFormat _
	   )
	
	   ' Accepts strDate as a valid date/time,
	   ' strFormat as the output template.
	   ' The function finds each item in the 
	   ' template and replaces it with the 
	   ' relevant information extracted from strDate.
	   ' You are free to use this code provided the following line remains
	   ' http://www.adopenstatic.com/resourc.../formatdate.asp
	
	   ' Template items
	   ' %m Month as a decimal no. 2
	   ' %M Month as a padded decimal no. 02
	   ' %B Full month name February
	   ' %b Abbreviated month name Feb   
	   ' %d Day of the month 23
	   ' %O Ordinal of day of month (eg st or rd or nd)
	   ' %j Day of the year 54
	   ' %Y Year with century 1998
	   ' %y Year without century 98
	   ' %w Weekday as integer (0 is Sunday)
	   ' %a Abbreviated day name Fri
	   ' %A Weekday Name Friday
	   ' %H Hour in 24 hour format 24
	   ' %h Hour in 12 hour format 12
	   ' %N Minute as an integer 01
	   ' %n Minute as optional if minute <> 00
	   ' %S Second as an integer 55
	   ' %P AM/PM Indicator PM
	
	   On Error Resume Next
	
	   Dim intPosItem
	   Dim int12HourPart
	   Dim str24HourPart
	   Dim strMinutePart
	   Dim strSecondPart
	   Dim strAMPM
	
	   ' Insert Month Numbers
	   strFormat = Replace(strFormat, "%m", DatePart("m", strDate), 1, -1, vbBinaryCompare)
	
	   ' Insert Padded Month Numbers
	   strFormat = Replace(strFormat, "%M", Right("0" & DatePart("m", strDate), 2), 1, -1, vbBinaryCompare)
	
	   ' Insert non-Abbreviated Month Names
	   strFormat = Replace(strFormat, "%B", MonthName(DatePart("m", strDate), False), 1, -1, vbBinaryCompare)
	
	   ' Insert Abbreviated Month Names
	   strFormat = Replace(strFormat, "%b", MonthName(DatePart("m", strDate), True), 1, -1, vbBinaryCompare)
	
	   ' Insert Day Of Month
	   strFormat = Replace(strFormat, "%d", DatePart("d",strDate), 1, -1, vbBinaryCompare)
	
	   ' Insert Day of Month Ordinal (eg st, th, or rd)
	   strFormat = Replace(strFormat, "%O", GetDayOrdinal(Day(strDate)), 1, -1, vbBinaryCompare)
	
	   ' Insert Day of Year
	   strFormat = Replace(strFormat, "%j", DatePart("y",strDate), 1, -1, vbBinaryCompare)
	
	   ' Insert Long Year (4 digit)
	   strFormat = Replace(strFormat, "%Y", DatePart("yyyy",strDate), 1, -1, vbBinaryCompare)
	
	   ' Insert Short Year (2 digit)
	   strFormat = Replace(strFormat, "%y", Right(DatePart("yyyy",strDate),2), 1, -1, vbBinaryCompare)
	
	   ' Insert Weekday as Integer (eg 0 = Sunday)
	   strFormat = Replace(strFormat, "%w", DatePart("w",strDate,1), 1, -1, vbBinaryCompare)
	
	   ' Insert Abbreviated Weekday Name (eg Sun)
	   strFormat = Replace(strFormat, "%a", WeekDayName(DatePart("w",strDate,1), True), 1, -1, vbBinaryCompare)
	
	   ' Insert non-Abbreviated Weekday Name
	   strFormat = Replace(strFormat, "%A", WeekDayName(DatePart("w",strDate,1), False), 1, -1, vbBinaryCompare)
	
	   ' Insert Hour in 24hr format
	   str24HourPart = DatePart("h",strDate)
	   If Len(str24HourPart) < 2 then str24HourPart = "0" & str24HourPart
	   strFormat = Replace(strFormat, "%H", str24HourPart, 1, -1, vbBinaryCompare)
	
	   ' Insert Hour in 12hr format
	   int12HourPart = DatePart("h",strDate) Mod 12
	   If int12HourPart = 0 then int12HourPart = 12
	   strFormat = Replace(strFormat, "%h", int12HourPart, 1, -1, vbBinaryCompare)
	
	   ' Insert Minutes
	   strMinutePart = DatePart("n",strDate)
	   If Len(strMinutePart) < 2 then strMinutePart = "0" & strMinutePart
	   strFormat = Replace(strFormat, "%N", strMinutePart, 1, -1, vbBinaryCompare)
	
	   ' Insert Optional Minutes
	   If CInt(strMinutePart) = 0 then
	      strFormat = Replace(strFormat, "%n", "", 1, -1, vbBinaryCompare)
	   Else
	      If CInt(strMinutePart) < 10 then strMinutePart = "0" & strMinutePart
	      strMinutePart = ":" & strMinutePart
	      strFormat = Replace(strFormat, "%n", strMinutePart, 1, -1, vbBinaryCompare)
	   End If
	
	   ' Insert Seconds
	   strSecondPart = DatePart("s",strDate)
	   If Len(strSecondPart) < 2 then strSecondPart = "0" & strSecondPart
	   strFormat = Replace(strFormat, "%S", strSecondPart, 1, -1, vbBinaryCompare)
	
	   ' Insert AM/PM indicator
	   If DatePart("h",strDate) >= 12 then
	      strAMPM = "PM"
	   Else
	      strAMPM = "AM"
	   End If
	   strFormat = Replace(strFormat, "%P", strAMPM, 1, -1, vbBinaryCompare)
	   FormatDate = strFormat
	End Function
	
	Function GetDayOrdinal( _
	   byVal intDay _
	   )
	
	   ' Accepts a day of the month 
	   ' as an integer and returns the 
	   ' appropriate suffix
	   On Error Resume Next
	
	   Dim strOrd
	
	   Select Case intDay
	   Case 1, 21, 31
	      strOrd = "st"
	   Case 2, 22
	      strOrd = "nd"
	   Case 3, 23
	      strOrd = "rd"
	   Case Else
	      strOrd = "th"
	   End Select
	
	   GetDayOrdinal = strOrd
	
	End Function
	
		function getDay(intDay)
		select case intDay
			case 1
				getDay = "Sunday"
			case 2
				getDay = "Monday"
			case 3
				getDay = "Tuesday"
			case 4
				getDay = "Wednesday"
			case 5
				getDay = "Thursday"
			case 6
				getDay = "Friday"
			case 7
				getDay = "Saturday"
			case else
				getDay = ""
		end select
	end function

	function getMonth(intDay)
		select case intDay
			case 1
				getMonth = "January"
			case 2
				getMonth = "February"
			case 3
				getMonth = "March"
			case 4
				getMonth = "April"
			case 5
				getMonth = "May"
			case 6
				getMonth = "June"
			case 7
				getMonth = "July"
			case 8
				getMonth = "August"
			case 9
				getMonth = "September"
			case 10
				getMonth = "October"
			case 11
				getMonth = "November"
			case 12
				getMonth = "December"
			case else
				getMonth = ""
		end select
	end function
 %>
	


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>

<body>
<%	myDate = formatDate(now(), "%d%O %B %Y") %>
<form name="theForm" action="act_register.asp" method="post">
<input type="text" name="date" value="<%= myDate %>">

</form>

</body>
</html>


This line.. myDate = formatDate(now(), "%d%O %B %Y") passes now() into the function formatDate() as well as our instructions on how we want the return date value formatted.

for full instructions on how to use formatDate(), check out this tutorial...
http://www.4guysfromrolla.com/webtech/022701-1.shtml

Hope this helps,
--

Reply With Quote
  #3  
Old June 15th, 2003, 06:35 AM
fmh002 fmh002 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 38 fmh002 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m
Reputation Power: 5
thnx for that, it helped a lot.

thnx once again,
fmh002

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > putting a formatted date in a text box


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway