Active Server Pages Programming (ASP)/Date display from database

Advertisement


Question
QUESTION: Hi Srini,
I have a site set up so that a person can log on and enter information on match fixtures and this information will be called from a database and displayed. Everything works fine but the date which is inputted and stored in the database in Irish format (dd/mm/yyyy) is displayed in American format (mm/dd/yyyy). I was wondering if you have any idea as to what I could do to fix this because it is messing up the sorting feature that I have included. I tried inputting the dates in American format but they were returned in American format, just not the dates that I had put in so I'm getting back dates like 2026 for matches that are taking place in three months time etc. Any help would be greatly appreciated.

Regards,

Colm.

ANSWER: you can get the date in dd/mm/yyyy from the database

if you are using SQL server using convert function you can get the right format.

Please let me know what type of database you are using..

-srini


---------- FOLLOW-UP ----------

QUESTION: Hi Srini,
It is only a very basic website with very low server interaction so I'm just using Microsoft Access. It was a friend of mine that set it up for me but he has no idea how to fix this problem. The date in the database is Irish format but when it diplays it has changed to American format.

Colm.

Answer
ok.

Just add the following line at top of your page

<%session.lcid=2057%>

this should display the date in dd/mm/yyy UK format.

If not here is the code

Example Usage:
<% = FormatMediumDate(rs("date")) %>

ASP Source Code:
<%
Function FormatMediumDate(DateValue)
   Dim strYYYY
   Dim strMM
   Dim strDD

       strYYYY = CStr(DatePart("yyyy", DateValue))

       strMM = CStr(DatePart("m", DateValue))
       If Len(strMM) = 1 Then strMM = "0" & strMM

       strDD = CStr(DatePart("d", DateValue))
       If Len(strDD) = 1 Then strDD = "0" & strDD

       FormatMediumDate = strMM & "/" & strDD & "/" & strYYYY

End Function
%>  
-srini

Active Server Pages Programming (ASP)

All Answers


Answers by Expert:


Ask Experts

Volunteer


Srini Nagarajan

Expertise

I can answer any kind of questions in ASP.NET, C#, VB.NET, SharePoint 2007, ASP, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience

Contact me if you need any custom development on ASP.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder.

©2012 About.com, a part of The New York Times Company. All rights reserved.