473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Date format

Any function on ASP to format date on dd/mm/yyyy?
The format (VB) function does not work on ASP ?

Thanks!
Feb 15 '08 #1
9 15706
"Paulo" <pr*****@uol.com.brwrote in message
news:Om**************@TK2MSFTNGP02.phx.gbl...
Any function on ASP to format date on dd/mm/yyyy?
The format (VB) function does not work on ASP ?
FormatDateTime() may meet your needs.

VBScript FormatDateTime Function
http://www.w3schools.com/vbscript/fu...atdatetime.asp

FormatDateTime(Now,2) = 02/15/2008 (mm/dd/yyyy) for me.

If you need dd/mm/yyyy then you may have to construct it
using DatePart(); for example, (where "x" is your date):

DatePart("d",x) & "/" & DatePart("m",x) & "/" & DatePart("yyyy",x)

Be aware that the day and month returned are not left-zero filled;
that is, today's date will appear as 15/2/2008 unless adjusted.
Feb 15 '08 #2
Any way to optimize it ?

<% sDia = ""
sMes = ""
sAno = ""
sData = ""
if not IsNull(rs("DT_EXAME")) then
sDia = Day(rs("DT_EXAME"))
sMes = Month(rs("DT_EXAME"))
sAno = Year(rs("DT_EXAME"))
if Len(sDia) = 1 then sDia = "0" & sDia
if Len(sMes) = 1 then sMes = "0" & sMes
sData = sDia & "/" & sMes & "/" & sAno
end if
%>

returns the dd/mm/yyyy coming from a db date field with left-zero filled

"McKirahan" <Ne**@McKirahan.comescreveu na mensagem
news:TK******************************@comcast.com. ..
"Paulo" <pr*****@uol.com.brwrote in message
news:Om**************@TK2MSFTNGP02.phx.gbl...
>Any function on ASP to format date on dd/mm/yyyy?
The format (VB) function does not work on ASP ?

FormatDateTime() may meet your needs.

VBScript FormatDateTime Function
http://www.w3schools.com/vbscript/fu...atdatetime.asp

FormatDateTime(Now,2) = 02/15/2008 (mm/dd/yyyy) for me.

If you need dd/mm/yyyy then you may have to construct it
using DatePart(); for example, (where "x" is your date):

DatePart("d",x) & "/" & DatePart("m",x) & "/" & DatePart("yyyy",x)

Be aware that the day and month returned are not left-zero filled;
that is, today's date will appear as 15/2/2008 unless adjusted.


Feb 15 '08 #3
http://dypso.free.fr/tech/asp_format_date_time-en.php

"Paulo" <pr*****@uol.com.brwrote in message news:ez****************@TK2MSFTNGP05.phx.gbl...
Any way to optimize it ?

<% sDia = ""
sMes = ""
sAno = ""
sData = ""
if not IsNull(rs("DT_EXAME")) then
sDia = Day(rs("DT_EXAME"))
sMes = Month(rs("DT_EXAME"))
sAno = Year(rs("DT_EXAME"))
if Len(sDia) = 1 then sDia = "0" & sDia
if Len(sMes) = 1 then sMes = "0" & sMes
sData = sDia & "/" & sMes & "/" & sAno
end if
%>

returns the dd/mm/yyyy coming from a db date field with left-zero filled

"McKirahan" <Ne**@McKirahan.comescreveu na mensagem news:TK******************************@comcast.com. ..
>"Paulo" <pr*****@uol.com.brwrote in message
news:Om**************@TK2MSFTNGP02.phx.gbl...
>>Any function on ASP to format date on dd/mm/yyyy?
The format (VB) function does not work on ASP ?

FormatDateTime() may meet your needs.

VBScript FormatDateTime Function
http://www.w3schools.com/vbscript/fu...atdatetime.asp

FormatDateTime(Now,2) = 02/15/2008 (mm/dd/yyyy) for me.

If you need dd/mm/yyyy then you may have to construct it
using DatePart(); for example, (where "x" is your date):

DatePart("d",x) & "/" & DatePart("m",x) & "/" & DatePart("yyyy",x)

Be aware that the day and month returned are not left-zero filled;
that is, today's date will appear as 15/2/2008 unless adjusted.



Feb 15 '08 #4
"Paulo" <pr*****@uol.com.brwrote in message
news:ez**************@TK2MSFTNGP05.phx.gbl...
Any way to optimize it ?

<% sDia = ""
sMes = ""
sAno = ""
sData = ""
if not IsNull(rs("DT_EXAME")) then
sDia = Day(rs("DT_EXAME"))
sMes = Month(rs("DT_EXAME"))
sAno = Year(rs("DT_EXAME"))
if Len(sDia) = 1 then sDia = "0" & sDia
if Len(sMes) = 1 then sMes = "0" & sMes
sData = sDia & "/" & sMes & "/" & sAno
end if
%>

returns the dd/mm/yyyy coming from a db date field with left-zero filled
[snip]

Please don't top post as it makes the conversation harder to follow.

Try this untested code:

<%
Response.Write rs("DT_EXAME") & " = " & MDY(rs("DT_EXAME"))

Function MDY(DT)
MDY = ""
If IsDate(DT) Then
MDY = Right(100+Day(DT),2) & "/" _
& Right(100+Month(DT),2) & "/" & Year(DT)
End If
End Function
%>
Feb 15 '08 #5
"Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot comwrote in message
news:13*************@corp.supernews.com...
http://dypso.free.fr/tech/asp_format_date_time-en.php
[snip]

Interesting idea; however, the following

<%
Response.Write "<li>" & FormatDateTime(Now,2)
Session.lcid=2057 '= UK English
Response.Write "<li>" & FormatDateTime(Now,2)
Session.lcid=1033 '= US English
Response.Write "<li>" & FormatDateTime(Now,2)
%>

returned (for me):

2/15/2008
15/02/08
2/15/2008
Feb 15 '08 #6
Paulo wrote:
Any function on ASP to format date on dd/mm/yyyy?
The format (VB) function does not work on ASP ?
http://www.aspfaq.com/show.asp?id=2313 vbscript
http://www.aspfaq.com/show.asp?id=2040 help with dates
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Feb 15 '08 #7
http://www.w3schools.com/asp/prop_lcid.asp

"McKirahan" <Ne**@McKirahan.comwrote in message news:od******************************@comcast.com. ..
"Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot comwrote in message
news:13*************@corp.supernews.com...
>http://dypso.free.fr/tech/asp_format_date_time-en.php

[snip]

Interesting idea; however, the following

<%
Response.Write "<li>" & FormatDateTime(Now,2)
Session.lcid=2057 '= UK English
Response.Write "<li>" & FormatDateTime(Now,2)
Session.lcid=1033 '= US English
Response.Write "<li>" & FormatDateTime(Now,2)
%>

returned (for me):

2/15/2008
15/02/08
2/15/2008


Feb 15 '08 #8
McKirahan wrote on 15 feb 2008 in microsoft.public.inetserver.asp.general:
<%
Response.Write rs("DT_EXAME") & " = " & MDY(rs("DT_EXAME"))

Function MDY(DT)
MDY = ""
If IsDate(DT) Then
MDY = Right(100+Day(DT),2) & "/" _
& Right(100+Month(DT),2) & "/" & Year(DT)
End If
End Function
%>
<%

response.write dateToString(#2008-02-15#, "dd/mm/yyyy") & "<br>"
response.write dateToString(#2008-02-16#, "m/d/yyyy")

function dateToString(d, frmt)
aF = split(frmt,"/")
for i=0 to 2
if aF(i) = "d" then aF(i) = day(d)
if aF(i) = "dd" then aF(i) = right("0"&day(d),2)
if aF(i) = "m" then aF(i) = month(d)
if aF(i) = "mm" then aF(i) = right("0"&month(d),2)
if aF(i) = "yyyy" then aF(i) = year(d)
next
dateToString= join(aF,"/")
end function

%>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 15 '08 #9
also see this:

http://www.4guysfromrolla.com/webtech/041001-1.shtml

"Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot comwrote in message news:13*************@corp.supernews.com...
http://www.w3schools.com/asp/prop_lcid.asp

"McKirahan" <Ne**@McKirahan.comwrote in message news:od******************************@comcast.com. ..
>"Jon Paal [MSMD]" <Jon nospam Paal @ everywhere dot comwrote in message
news:13*************@corp.supernews.com...
>>http://dypso.free.fr/tech/asp_format_date_time-en.php

[snip]

Interesting idea; however, the following

<%
Response.Write "<li>" & FormatDateTime(Now,2)
Session.lcid=2057 '= UK English
Response.Write "<li>" & FormatDateTime(Now,2)
Session.lcid=1033 '= US English
Response.Write "<li>" & FormatDateTime(Now,2)
%>

returned (for me):

2/15/2008
15/02/08
2/15/2008



Feb 15 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to...
2
by: amith | last post by:
hi I have written javascript for comparing two dates in US format and finding out whether the start date is greater than the end date and vice versa. In this attempt i have instantiated the...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
3
by: Lyn | last post by:
Hi, I am developing a project in which I am checking for records with overlapping start/end dates. Record dates must not overlap date of birth, date of death, be in the future, and must not...
5
by: Macca | last post by:
Hi, I have a table which has a date/time field. I am storing them as follows :- 01/01/2005 11:25 01/01/2005 19:44 02/01/2005 05:04
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
20
by: andreas | last post by:
When I copy a vb.net project using date formats from one PC with a windows date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I get errors. How can I change for a while in the...
30
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This problem happens in either Access or SQL Server. In the...
4
by: OzNet | last post by:
I have some functions to calculate the working days in a given period. This includes a table that is queried to calculate the number of public holidays that don’t occur on a weekend. If I test...
11
ollyb303
by: ollyb303 | last post by:
Hello, I am using a dynamic crosstab report to track performance statistics for my company and I have hit a problem. I would like the option to track stats daily (for the last 7 complete...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.