Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Formating Dates?

Posted on 2002-06-20
32
Medium Priority
?
512 Views
Last Modified: 2008-03-17
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
Comment
Question by:mercia
  • 10
  • 8
  • 6
  • +4
32 Comments
 
LVL 30

Expert Comment

by:third
ID: 7095110
could you show us the "DoDateTime" function?
0
 
LVL 20

Expert Comment

by:Michel Sakr
ID: 7095136
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
 
LVL 30

Expert Comment

by:third
ID: 7095140
also check your settings for Long Date in the Control Panel > Regional Settings > Date
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Expert Comment

by:ThomasEU
ID: 7095142
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
 
LVL 4

Expert Comment

by:jkunal
ID: 7095148
<%=FormatDateTime(cdate(DoDateTime((UCCart1.GetColumnValue("Date",UCCart1__i)), 2, -1)),1)%>
0
 
LVL 30

Expert Comment

by:third
ID: 7095157
or probably just

<%=FormatDateTime(cdate(UCCart1.GetColumnValue("Date",UCCart1__i)),1)%>
0
 

Author Comment

by:mercia
ID: 7095165
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
 
LVL 30

Expert Comment

by:third
ID: 7095172
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
 
LVL 4

Expert Comment

by:jkunal
ID: 7095176
if you can write the code for DoDateTime, it would be helpful.
0
 

Expert Comment

by:ThomasEU
ID: 7095197
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
 
LVL 30

Expert Comment

by:third
ID: 7095205
sorry it returns date type so to view it you could,

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

and give us what is rendered.
0
 

Expert Comment

by:ThomasEU
ID: 7095216
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
 

Author Comment

by:mercia
ID: 7095318
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
 
LVL 4

Expert Comment

by:jkunal
ID: 7095350
pass this LCID to your DoDateTime function 1033
0
 

Author Comment

by:mercia
ID: 7095376
Do not understand?  pass what to what and where?
0
 
LVL 4

Expert Comment

by:jkunal
ID: 7095393
Use this function

<%= DoDateTime((UCCart1.GetColumnValue("Date",UCCart1__i)), 1, 1033) %>
0
 

Author Comment

by:mercia
ID: 7095423
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
 
LVL 4

Expert Comment

by:jkunal
ID: 7095449
try this code
<%
Session.LCID = 1033
%>
<%
=FormatDateTime(CDate(UCCart1.GetColumnValue("Date",UCCart1__i)),1)
%>
0
 
LVL 4

Expert Comment

by:jkunal
ID: 7095462
there was an extra bracket maybe this will work
 
<td width="118"><%= DoDateTime(UCCart1.GetColumnValue("Date",UCCart1__i), 1, 1033) %></td>
0
 

Author Comment

by:mercia
ID: 7095771
Sorry no change with either option.  The extra bracket was put in by UltraDev when I tried to format the value.
0
 
LVL 4

Expert Comment

by:jkunal
ID: 7096028
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
 
LVL 30

Expert Comment

by:third
ID: 7097571
have you checked the date formats in your server's regional settings?

again it is,

Control Panel > Regional Settings > Date Tab
0
 

Expert Comment

by:ben_1
ID: 7102083
So this line of code doesn't work????

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

Ben
0
 

Author Comment

by:mercia
ID: 7103220
Sorry no that code does not work, I get VBScript error type mismatch??
0
 
LVL 4

Expert Comment

by:jkunal
ID: 7103222
just print this and let us know what is the output.

UCCart1.GetColumnValue("Date",UCCart1__i)
0
 

Expert Comment

by:ben_1
ID: 7104839
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
 

Author Comment

by:mercia
ID: 7106639
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
 
LVL 4

Expert Comment

by:jkunal
ID: 7106665
can you just print the date, and write the output here, may be that will make some sense
0
 

Accepted Solution

by:
mercia earned 0 total points
ID: 7107808
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
 
LVL 4

Expert Comment

by:jkunal
ID: 7109587
i still want to see what date was printed without the formatting
0
 
LVL 4

Expert Comment

by:Wakie
ID: 9355373
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question