Wrox Programmer Forums
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Dreamweaver (all versions) section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 14th, 2005, 12:49 PM
Authorized User
 
Join Date: Jan 2005
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date Format Modification

Hello Everyone!

Using the following code

<%= DoDateTime((rsAdmin.Fields.Item("userLastUpdate"). Value), 1, 2057) %>

I can get (say) "26 September 2005" from the (recordset connected to a) database.

What changes should I do in the code to get "26 Sep 05" instead, please?!

Thanks in advance!
fskilnik


P.S.: one very easy (ASP) coding tutorial for OTHER dates formatting may be
found in http://www.codetoad.com/asp/format_date_time.asp

To get (for instance) "Friday, October 14, 2005" we could code:

<%
Dim todayDate
todayDate=now()
%>

and then use this new variable inside "FormatDateTime(todayDate,1)".

The problem is that I could not find a number to put in the place of this "1" to get
"DAY MONTH-ABREVIATED YEAR-WITH-2DIGITS"

(Sorry, Imar, I see this is ASP stuff, not Dreamweaver but... I guess many users may benefit from this theme when using Dreamweaver, ok?!)
 
Old October 14th, 2005, 04:54 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi fskilnik,

AFAIK, there is no internal way to do this.

However it shouldn't be hard to create your function. Take a look here for a list of useful functions you have available:

http://www.w3schools.com/vbscript/vb..._functions.asp

Also, take a look here:

http://www.ilovejackdaniels.com/asp/...mat-functions/

for a suggestion how to approach such a function.....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old October 16th, 2005, 12:50 PM
Authorized User
 
Join Date: Jan 2005
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello, Imar!

Thanks for the quick reply and the great links! I adapted the second one to my needs and... yes! It worked perfectly! :)

Thank you very much indeed.

Best Regards,
fskilnik

P.S.: for the interested readers, I did the following:

01) Created a "functions.asp" file containing exactly the code written below (at the end of this post) ;

02) Put in my "*.asp" page the instruction "to read from it"



03) Put the code

<%=FormatingDate("%d %M %y", UDate((rsInvestorData.Fields.Item("dealingDate").V alue)))%>

to read my recordset "rsInvestorData" in the (desired) format "03 Jan 05".

That´s it!!

---------------- All Code in functions.asp ------------------------

<%

function UDate(oldDate)
UDate = DateDiff("s", "01/01/1970 00:00:00", oldDate)
end function


function unUDate(intTimeStamp)
unUDate = DateAdd("s", intTimeStamp, "01/01/1970 00:00:00")
end function


function FormatingDate(format, intTimeStamp)
Dim monthname()
Redim monthname(12)
monthname(1) = "January"
monthname(2) = "February"
monthname(3) = "March"
monthname(4) = "April"
monthname(5) = "May"
monthname(6) = "June"
monthname(7) = "July"
monthname(8) = "August"
monthname(9) = "September"
monthname(10) = "October"
monthname(11) = "November"
monthname(12) = "December"

dim unUDate, A

dim OriginalLocale
dim res
OriginalLocale = GetLocale
res = SetLocale("en-gb")

if not (isnumeric(intTimeStamp)) then
if isdate(intTimeStamp) then
intTimeStamp = DateDiff("s", "01/01/1970 00:00:00", intTimeStamp)
else
response.write "Date Invalid"
exit function
end if
end if

if (intTimeStamp=0) then
unUDate = now()
else
unUDate = DateAdd("s", intTimeStamp, "01/01/1970 00:00:00")
end if

unUDate = trim(unUDate)

dim startM : startM = 1
dim startD : startD = InStr(startM, unUDate, "/")+1
dim startY : startY = InStr(startD, unUDate, "/")+1
dim dateDay : dateDay = mid(unUDate, 1, (startM + 1))
dim dateMonth : dateMonth = mid(unUDate, startD, ((startY - 1) - startD))
dim dateYear : dateYear = mid(unUDate, startY, 4)

format = replace(format, "%y", right(dateYear, 2))
format = replace(format, "%m", dateMonth)

format = replace(format, "%M", left(monthname(cint(dateMonth)), 3))
format = replace(format, "%d", dateDay)

FormatingDate = format
res = SetLocale(OriginalLocale)

end function

%>





Similar Threads
Thread Thread Starter Forum Replies Last Post
date format differs, need to force format somehow patricolsson ASP.NET 2.0 Basics 1 December 3rd, 2009 12:53 AM
Convert British format date to American format? fyr PHP How-To 0 December 19th, 2007 03:17 PM
Format Date Tim Johnson Access 1 December 17th, 2007 08:18 AM
How to give Date format while entering date Subuana Beginning VB 6 4 March 17th, 2006 07:25 AM
date format differs, need to force format somehow patricolsson HTML Code Clinic 2 January 12th, 2006 05:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.