Solved

Formating Dates?

Posted on 2002-06-20
32
503 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
Comment Utility
could you show us the "DoDateTime" function?
0
 
LVL 20

Expert Comment

by:Silvers5
Comment Utility
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
Comment Utility
also check your settings for Long Date in the Control Panel > Regional Settings > Date
0
 

Expert Comment

by:ThomasEU
Comment Utility
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
Comment Utility
<%=FormatDateTime(cdate(DoDateTime((UCCart1.GetColumnValue("Date",UCCart1__i)), 2, -1)),1)%>
0
 
LVL 30

Expert Comment

by:third
Comment Utility
or probably just

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

Author Comment

by:mercia
Comment Utility
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
Comment Utility
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
Comment Utility
if you can write the code for DoDateTime, it would be helpful.
0
 

Expert Comment

by:ThomasEU
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
pass this LCID to your DoDateTime function 1033
0
 

Author Comment

by:mercia
Comment Utility
Do not understand?  pass what to what and where?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 4

Expert Comment

by:jkunal
Comment Utility
Use this function

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

Author Comment

by:mercia
Comment Utility
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
Comment Utility
try this code
<%
Session.LCID = 1033
%>
<%
=FormatDateTime(CDate(UCCart1.GetColumnValue("Date",UCCart1__i)),1)
%>
0
 
LVL 4

Expert Comment

by:jkunal
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry no that code does not work, I get VBScript error type mismatch??
0
 
LVL 4

Expert Comment

by:jkunal
Comment Utility
just print this and let us know what is the output.

UCCart1.GetColumnValue("Date",UCCart1__i)
0
 

Expert Comment

by:ben_1
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
i still want to see what date was printed without the formatting
0
 
LVL 4

Expert Comment

by:Wakie
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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/…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now