Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 513
  • Last Modified:

Formating Dates?

I have been using ultraDev to create some .asp pages all has been well until I tried formating a date displayed in my shopping cart. The code wrote for it is:

<%= DoDateTime((UCCart1.GetColumnValue("Date",UCCart1__i)), 2, -1) %>

The response given by the browser is:
Tue Sep 17 00:00:00 UTC+0100 2002

I would like to know why DoDate is doing this and what I have to do to make the date appear like:
Tue Sep 17 2002

Can anyone help????????
0
mercia
Asked:
mercia
  • 10
  • 8
  • 6
  • +4
1 Solution
 
thirdCommented:
could you show us the "DoDateTime" function?
0
 
Michel SakrCommented:
it seems you are using formatdatetime? or the timestamp logged is a long date

do it this way:

zDate = weekdayname(weekday(zDate),1,1) & " " & MonthName(Month(zDate)) & " " & Day(zDate) & " " & Year(zDate)


zDate must be a datetime value otherwise if it's a string in a correct syntax convert it first to date using

zDate = cDate(zDate)





0
 
thirdCommented:
also check your settings for Long Date in the Control Panel > Regional Settings > Date
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ThomasEUCommented:
I would suggest that you use the built-in function FormatDateTime in VBScript. This function is however, depending on the International settings of the computer on which the ASP script is run, but it works with the named formats (vbShortDate, vbGeneralDate, vbLongDate) in most cases.
0
 
jkunalCommented:
<%=FormatDateTime(cdate(DoDateTime((UCCart1.GetColumnValue("Date",UCCart1__i)), 2, -1)),1)%>
0
 
thirdCommented:
or probably just

<%=FormatDateTime(cdate(UCCart1.GetColumnValue("Date",UCCart1__i)),1)%>
0
 
merciaAuthor Commented:
I have tried FormatDateTime but it did not seem to work, could you provide an example of how it would work with the variable passed UCCart1.GetColumnValue("Date",UCCart1__i) as I believe it is here where the proble may lie????  If you could provide an example of what I should put I would be gratefull.  Thanks
0
 
thirdCommented:
have u tried mine?
or maybe try doing
<%=UCCart1.GetColumnValue("Date",UCCart1__i)%> and give us the exact value rendered so we can easily determine.
0
 
jkunalCommented:
if you can write the code for DoDateTime, it would be helpful.
0
 
ThomasEUCommented:
You could try a custom function like this:

Function MyDate(varDate)

If Not IsDate(varDate) Then
     MyDate = "Invalid Date"
Else
     intWeekDay = WeekDay(varDate)
     
     Select Case intWeekDay
          Case vbSunday
               strDay = "Sun"
          Case vbMonday
               strDay = "Mon"          
          Case vbTuesday
               strDay = "Tue"
          Case vbWedensday
               strDay = "Wed"
          Case vbThursday
               strDay = "Thu"
          Case vbFriday
               strDay = "Fri"
          Case vbSaturday
               strDay = "Sat"
     End Select

     MyDate = strDay & " " & MonthName(Month(varDate), True) & " " & Day(varDate) & " " & Year(varDate)    
     
End If

End Function

To test the function with the current date:

Response.Write MyDate(date())

A call like this should work:

Response.Write MyDate(UCCart1.GetColumnValue("Date",UCCart1__i))
0
 
thirdCommented:
sorry it returns date type so to view it you could,

<%=CStr(UCCart1.GetColumnValue("Date",UCCart1__i))%>

and give us what is rendered.
0
 
ThomasEUCommented:
Actually the function could be improved a little :-)

Function MyDate(varDate)

If Not IsDate(varDate) Then
     MyDate = "Invalid Date"
Else
     
     MyDate = WeekDayName(WeekDay(varDate), True, vbUseSystem) & " " & MonthName(Month(varDate), True) & " " & Day(varDate) & " " & Year(varDate)    
     
End If

End Function
0
 
merciaAuthor Commented:
Here is the DoDate function which comes with ultraDev can you see what is wrong with it and why it displays this extra information?

function DoDateTime(str, nNamedFormat, nLCID)                    
     dim strRet                                        
     dim nOldLCID                                        
                                                 
     strRet = str                                        
     If (nLCID > -1) Then                                  
          oldLCID = Session.LCID                              
     End If                                            
                                                 
     On Error Resume Next                                  
                                                 
     If (nLCID > -1) Then                                  
          Session.LCID = nLCID                              
     End If                                            
                                                 
     If ((nLCID < 0) Or (Session.LCID = nLCID)) Then                    
          strRet = FormatDateTime(str, nNamedFormat)              
     End If                                            
                                                 
     If (nLCID > -1) Then                                  
          Session.LCID = oldLCID                              
     End If                                            
                                                 
     DoDateTime = strRet                                  
End Function                    
0
 
jkunalCommented:
pass this LCID to your DoDateTime function 1033
0
 
merciaAuthor Commented:
Do not understand?  pass what to what and where?
0
 
jkunalCommented:
Use this function

<%= DoDateTime((UCCart1.GetColumnValue("Date",UCCart1__i)), 1, 1033) %>
0
 
merciaAuthor Commented:
Hi Here is me line of code:
 <td width="118"><%= DoDateTime((UCCart1.GetColumnValue("Date",UCCart1__i)), 1, 1033) %></td>

There still is no change here is my response
Mon Nov 4 00:00:00 UTC 2002

What does 1033 do?
0
 
jkunalCommented:
try this code
<%
Session.LCID = 1033
%>
<%
=FormatDateTime(CDate(UCCart1.GetColumnValue("Date",UCCart1__i)),1)
%>
0
 
jkunalCommented:
there was an extra bracket maybe this will work
 
<td width="118"><%= DoDateTime(UCCart1.GetColumnValue("Date",UCCart1__i), 1, 1033) %></td>
0
 
merciaAuthor Commented:
Sorry no change with either option.  The extra bracket was put in by UltraDev when I tried to format the value.
0
 
jkunalCommented:
hmmmmm...

This function will work whatever.
Format your date as u like.

<%
Function displayDate(val)
     
     Dim str
     
     val = CDate(val)

     valWeek =  weekday(val,0)    

     Select case valWeek
          Case "1" str = "Sunday "
          Case "2" str = "Monday "
          Case "3" str = "Tuesday "
          Case "4" str = "Wednesday "
          Case "5" str = "Thursday "
          Case "6" str = "Friday "
          Case "7" str = "Saturday "
     end select          

     valMonth = Month(val)

     Select case valMonth
          Case "1" str = str & "Jan "
          Case "2" str = str & "Feb "
          Case "3" str = str & "Mar "
          Case "4" str = str & "Apr "
          Case "5" str = str & "May "
          Case "6" str = str & "Jun "
          Case "7" str = str & "Jul "
          Case "8" str = str & "Aug "
          Case "9" str = str & "Sep "
          Case "10" str = str & "Oct "
          Case "11" str = str & "Nov "
          Case "12" str = str & "Dec "
     end select          

     str = str & day(val) & " "

     str = str &  Year(val)
     
     displayDate = str
End Function

Response.Write displayDate(UCCart1.GetColumnValue("Date",UCCart1__i))
%>
0
 
thirdCommented:
have you checked the date formats in your server's regional settings?

again it is,

Control Panel > Regional Settings > Date Tab
0
 
ben_1Commented:
So this line of code doesn't work????

<td width="118"><%= Formatdatetime(DoDateTime((UCCart1.GetColumnValue("Date",UCCart1__i)), 1, 1033),vbshortdate) %></td>

Ben
0
 
merciaAuthor Commented:
Sorry no that code does not work, I get VBScript error type mismatch??
0
 
jkunalCommented:
just print this and let us know what is the output.

UCCart1.GetColumnValue("Date",UCCart1__i)
0
 
ben_1Commented:
Sorry, you would need to convert it to a date... Try this... I think a very similar one was tried above though.

<td width="118"><%= Formatdatetime(CDate(DoDateTime((UCCart1.GetColumnValue("Date",UCCart1__i)), 1, 1033)),vbshortdate) %></td>

But again, the vbshortdate variable will only tell it what to put based on your individual computer's regional settings.  Have you tried changing your regional settings or on anothoer computer to see if the same results occur??

One more question... How was the date entered?  Was it put into the field via user entry or some type of generated date?
0
 
merciaAuthor Commented:
Sorry no that code does not work, I get VBScript error type mismatch on CDate?? The date comes from a database, it is displayed correctly on the previous page, infact the DoDateTime function works correctly on the previous page, but once the selected item is clicked and transfer to the next page the date is displayed in this funny way?????
0
 
jkunalCommented:
can you just print the date, and write the output here, may be that will make some sense
0
 
merciaAuthor Commented:
I have managed to solve the problem myself I have found that the only way to solve this is to format the data at source ie within the recordset.  Although the information is stored as a date it would appear that the cart where the information is displayed translates it.  Thank you all for you help in trying to solve this problem.
0
 
jkunalCommented:
i still want to see what date was printed without the formatting
0
 
WakieCommented:
It appears this question has been abandoned.

I will leave a recommendation in the Cleanup topic area that this question will be:

- Question PAQ'd and points forfeited - Solution not provided.

Please leave any comments here within the next seven days.

DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Wakie,
EE Cleanup Volunteer.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 10
  • 8
  • 6
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now