ASP date fun

Ok, so I still code in classic ASP – don’t shoot me!  The main reason I do this is because it’s been a long time since I was actually employed to code for a living and when you have a full-time job that calls for occasional web development you kind of default to what you know, don’t you? (I will pickup some ASP.NET stuff and bring myself up to date honest!)

So todays little puzzle has been how to display part of a date variable – I’m using a CCS trick to display a calendar style date block but needed to extract parts of a date and display them differently – I started looking at the day of the week. The variable holds the date as DD/MM/YY, but I wanted to display the name of the day, first off I stumbled on this solution;

currdate = now()
currid = weekday(currdate)
currname = weekdayname(currid)
response.write “today is” & currname

But since I’m doing this on a database field and already have a date variable I dropped line one – I still thought it was a little too complicated, then stumbled across

weekdayname(weekday(date))

This worked perfectly so;

weekdayname(weekday(db1.Fields.Item(“db1date”).Value))

Is exactly what I needed. Fortunately I found shortly afterwards there is indeed a similar function for Month.

monthname(month(db1.Fields.Item(“db1date”).Value))

Is the code for that, but it was still not quite there, the full name was making the CSS block look out-of-place, fortunately there’s a shortener;

monthname(month(db1.Fields.Item(“db1date”).Value),true)

Adding in the, true option tells the function to display the shortened version of the month – and this was (bar a bit of text resizing and positional altering) all I needed to do, now I have a dynamic CSS powered calendar tab on my press release pages.

http://psacake.com/web/functions.asp?id=38
http://www.webmasterworld.com/forum47/1012.htm
http://snook.ca/archives/html_and_css/css-text-rotation

pr.Fields.Item(“prdate”).Value

Leave a Comment

THE PERSONAL BLOG OF CORNWALL-BASED COMPANY DIRECTOR // CHRIS RICKARD