PC Review


Reply
Thread Tools Rate Thread

Date Format dd/MM/yyyy

 
 
Kwong
Guest
Posts: n/a
 
      10th May 2005
I am using frontpage with access to save some data, including dates. I
need the date to be saved in the format dd/MM/yyyy (and all
calculations and queries to be compatible) so I used the FormatDateTime
function. I changed my regional settings such that the short date is
dd/MM/yyyy but, it still uses the m/d/yyyy for an unknown reason.

on one page, i have the user use three drop down menus to input day,
month, and year. these are sent to another page - and below is what I
have coded. Please let me know what I am doing wrong.
Thank you.

<%

dim myDate(2)
dim strQty
dim strDate, stringDate


strQty = request("Qty")

myDate(0) = request("Date")
myDate(1) = request("Month")
myDate(2) = request("Year")

strDate = Join(myDate, "-")
strDate = FormatDateTime(strDate, 2)
stringDate = FormatDateTime(strDate, 1)

response.write "<p>date is: --> : " &strDate& " "

if IsDate(strDate) = FALSE then

response.write "<p>The date " & strDate & " does not exist <p> Please
enter a new date.<p>"
response.write "<p>Return to <a href='date.htm'>Form</a> or click
back<p>"

else

response.write "<p>all is good <p>"
response.write "<p>i repeat, the date entered is: " & stringDate & " "

session("Date") = strDate
session("Qty") = strQty
response.write "<p>qty entered is: " &strQty& " "

end if


response.write "<p><a href='index.htm'>Homepage</a></p>"

%>

 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      10th May 2005
Hi Kwong,

Interesting question. You seem to have done your homework. Format 1 is
vbLongDate, which should use your computer's regional settings. Format 2 is
vbShortDate, which should also use your computer's regional settings. My
first question would be, where are you requesting this page from? If the ASP
page is on your local computer, it should display the date as you expect. On
the other hand, if the ASP page is on a remote computer, it will use that
computer's regional settings. Once the date has been formatted, it is a
string in an HTML page, and it will not "translate" to the browser
computer's regional settings.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"Kwong" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am using frontpage with access to save some data, including dates. I
> need the date to be saved in the format dd/MM/yyyy (and all
> calculations and queries to be compatible) so I used the FormatDateTime
> function. I changed my regional settings such that the short date is
> dd/MM/yyyy but, it still uses the m/d/yyyy for an unknown reason.
>
> on one page, i have the user use three drop down menus to input day,
> month, and year. these are sent to another page - and below is what I
> have coded. Please let me know what I am doing wrong.
> Thank you.
>
> <%
>
> dim myDate(2)
> dim strQty
> dim strDate, stringDate
>
>
> strQty = request("Qty")
>
> myDate(0) = request("Date")
> myDate(1) = request("Month")
> myDate(2) = request("Year")
>
> strDate = Join(myDate, "-")
> strDate = FormatDateTime(strDate, 2)
> stringDate = FormatDateTime(strDate, 1)
>
> response.write "<p>date is: --> : " &strDate& " "
>
> if IsDate(strDate) = FALSE then
>
> response.write "<p>The date " & strDate & " does not exist <p> Please
> enter a new date.<p>"
> response.write "<p>Return to <a href='date.htm'>Form</a> or click
> back<p>"
>
> else
>
> response.write "<p>all is good <p>"
> response.write "<p>i repeat, the date entered is: " & stringDate & " "
>
> session("Date") = strDate
> session("Qty") = strQty
> response.write "<p>qty entered is: " &strQty& " "
>
> end if
>
>
> response.write "<p><a href='index.htm'>Homepage</a></p>"
>
> %>
>



 
Reply With Quote
 
Jon Spivey
Guest
Posts: n/a
 
      10th May 2005
Hi,
you can't save a date to a database in any format - MS databases store dates
as numbers and assume they're in US mm/dd/yyyy format. First we need to get
the date into the database correctly. To avoid confusion it's much easier to
use the ISO date format yyyy-mm-dd so today is 2005-05-10 - this format is
understood by every database and avoids the issue of 10/5/2005 being 10 May
or 5 October

<%
day = request("Date")
month = request("Month")
year = request("Year")
d = year & "-" & month & "-" & day
if isdate(d) then
' it's a date
' stick it into the database
end if
%>

Now we've got the date stored we can display it in the right format

SELECT Format(DateField, 'dd/mm/yyyy') AS UkDate

You can format however you like here - eg long dates, short dates etc

--
Cheers,
Jon
Microsoft MVP

"Kwong" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am using frontpage with access to save some data, including dates. I
> need the date to be saved in the format dd/MM/yyyy (and all
> calculations and queries to be compatible) so I used the FormatDateTime
> function. I changed my regional settings such that the short date is
> dd/MM/yyyy but, it still uses the m/d/yyyy for an unknown reason.
>
> on one page, i have the user use three drop down menus to input day,
> month, and year. these are sent to another page - and below is what I
> have coded. Please let me know what I am doing wrong.
> Thank you.
>
> <%
>
> dim myDate(2)
> dim strQty
> dim strDate, stringDate
>
>
> strQty = request("Qty")
>
> myDate(0) = request("Date")
> myDate(1) = request("Month")
> myDate(2) = request("Year")
>
> strDate = Join(myDate, "-")
> strDate = FormatDateTime(strDate, 2)
> stringDate = FormatDateTime(strDate, 1)
>
> response.write "<p>date is: --> : " &strDate& " "
>
> if IsDate(strDate) = FALSE then
>
> response.write "<p>The date " & strDate & " does not exist <p> Please
> enter a new date.<p>"
> response.write "<p>Return to <a href='date.htm'>Form</a> or click
> back<p>"
>
> else
>
> response.write "<p>all is good <p>"
> response.write "<p>i repeat, the date entered is: " & stringDate & " "
>
> session("Date") = strDate
> session("Qty") = strQty
> response.write "<p>qty entered is: " &strQty& " "
>
> end if
>
>
> response.write "<p><a href='index.htm'>Homepage</a></p>"
>
> %>
>



 
Reply With Quote
 
Kwong
Guest
Posts: n/a
 
      11th May 2005
Hi,

I am using the ASP on my own computer.
I am trying to use the SELECT Format(DateField, 'dd/mm/yyyy') AS UkDate
statement that you suggested, but i do not know where to add it. i
tried to add it as part of the main SQL statement when i am listing the
records in the database - but that does not work.

if i leave it as is, it displays the info but the date is d/m/yyyy

this is what i have:
.....

strSQL = "SELECT * FROM math ORDER BY id;"

' strSQL = "SELECT Format(date, 'dd/mm/yyyy') AS UkDate FROM math ORDER
BY id;"
' date = FormatDateTime(date, 1)

Set rstDBEdit = Server.CreateObject("ADODB.Recordset")
rstDBEdit.Open strSQL, CONN_STRING, adOpenForwardOnly, adLockReadOnly,
adCmdText
%>

<table border="1" cellspacing="2" cellpadding="2">
<thead>
<tr>
<th>id</th>
<th>Qty</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<%

Do While Not rstDBEdit.EOF
%>
<tr>
<% ' date = Format(date, 'dd/mm/yyyy')%>
<td><%= rstDBEdit.Fields("id").Value %>&nbsp;</td>
<td><%= rstDBEdit.Fields("qty").Value %>&nbsp;</td>
<td><%= rstDBEdit.Fields("date").Value %>&nbsp;</td>

</tr>
<%
rstDBEdit.MoveNext

Loop

%>

</tbody>
<tfoot>
<tr>

</tr>
</tfoot>
</table>
<%
rstDBEdit.Close
Set rstDBEdit = Nothing
%>

Thanks a lot for all the help.

 
Reply With Quote
 
Jon Spivey
Guest
Posts: n/a
 
      11th May 2005
Hi,

Ideally you should list all the fields you want in your select rather than
using select * - it's more efficient. So you'd have something like
select field1, field2, field3, Format(DateField, 'dd/mm/yyyy') AS UkDate
from table
this will give you a field called UkDate containg the formatted date

If you want to stick with select * you can do
select *, Format(DateField, 'dd/mm/yyyy') AS UkDate from table
This will give you all the fields in your table plus the UkDate field

--
Cheers,
Jon
Microsoft MVP

"Kwong" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I am using the ASP on my own computer.
> I am trying to use the SELECT Format(DateField, 'dd/mm/yyyy') AS UkDate
> statement that you suggested, but i do not know where to add it. i
> tried to add it as part of the main SQL statement when i am listing the
> records in the database - but that does not work.
>
> if i leave it as is, it displays the info but the date is d/m/yyyy
>
> this is what i have:
> ....
>
> strSQL = "SELECT * FROM math ORDER BY id;"
>
> ' strSQL = "SELECT Format(date, 'dd/mm/yyyy') AS UkDate FROM math ORDER
> BY id;"
> ' date = FormatDateTime(date, 1)
>
> Set rstDBEdit = Server.CreateObject("ADODB.Recordset")
> rstDBEdit.Open strSQL, CONN_STRING, adOpenForwardOnly, adLockReadOnly,
> adCmdText
> %>
>
> <table border="1" cellspacing="2" cellpadding="2">
> <thead>
> <tr>
> <th>id</th>
> <th>Qty</th>
> <th>Date</th>
> </tr>
> </thead>
> <tbody>
> <%
>
> Do While Not rstDBEdit.EOF
> %>
> <tr>
> <% ' date = Format(date, 'dd/mm/yyyy')%>
> <td><%= rstDBEdit.Fields("id").Value %>&nbsp;</td>
> <td><%= rstDBEdit.Fields("qty").Value %>&nbsp;</td>
> <td><%= rstDBEdit.Fields("date").Value %>&nbsp;</td>
>
> </tr>
> <%
> rstDBEdit.MoveNext
>
> Loop
>
> %>
>
> </tbody>
> <tfoot>
> <tr>
>
> </tr>
> </tfoot>
> </table>
> <%
> rstDBEdit.Close
> Set rstDBEdit = Nothing
> %>
>
> Thanks a lot for all the help.
>



 
Reply With Quote
 
Kwong
Guest
Posts: n/a
 
      16th May 2005
that works!
thank you all very much.

 
Reply With Quote
 
 
 
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I change date from mm/dd/yyyy to dd:mm:yyyy format in Excel =?Utf-8?B?SmFjayBXaWxzb24=?= Microsoft Excel New Users 4 18th Jul 2006 01:57 PM
opening excel file -> date format problem: DD/MM/YYYY vs MM/DD/YYYY yung Microsoft Excel Programming 2 18th Mar 2005 12:50 PM
Date format : field set to dd/mm/yyyy, but query wants mm/dd/yyyy aa Microsoft Access Database Table Design 2 29th Dec 2003 10:53 AM
Date format : field set to dd/mm/yyyy, but query wants mm/dd/yyyy aa Microsoft Access Queries 2 29th Dec 2003 10:53 AM
Date format : field set to dd/mm/yyyy, but query wants mm/dd/yyyy aa Microsoft Access 2 29th Dec 2003 10:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:21 AM.