SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    vi
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Change Date from mm/dd/yyyy to dd - mm

    I need to change my code to read my date from mm/dd/yyyy to DD - MM

    CODE:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

    <%

    do while not rs.EOF

    ':: read db record
    on error resume next
    DateAdded = rs("DateAdded")
    on error goto 0

    %>





    <tr>
    <td class='SectionTDNews'>




    <% DateAdded = left(DateAdded,4) %><% title = left(title,22) %><a href="content.do?contentid=<% =ContentId %>" class='SectionFontNews'><% =DateAdded %> - <img src="styles/nse/images/edit-m-stx-xx.gif" border="0"> <% =Title %></a>..
    </td>
    </tr>

  2. #2
    SitePoint Zealot trekmp's Avatar
    Join Date
    Dec 2005
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a function I wrote ages again to format dates, can easily be altered to allow for new formats

    Code:
    '================================================================================
    '		Setting the date	
    '================================================================================
    	Public Function DateFormat(sTheDate,iFormat)
    		Dim y,m,d,mi,myMonth,myDay,dw
    		'=== Validation
    		If NOT IsDate(sTheDate) AND sTheDate<>"" Then 
    			Response.Write("Not a true date format (" & sTheDate & "). All Stop!!!")
    			Response.End
    		End if
    		If iFormat<0 OR iFormat>7 then
    			Response.Write("Format must be between 0-7 not " & iFormat & ". All Stop!!!")
    			Response.End
    		End if
    		'=== Do the formatting
    		myDay=Array("","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
    		myMonth=Array("","January","Feburary","March","April","May","June","July","August","September","October","November","December")
    		'Checks to see if there is a date
    		If sTheDate="" then	'#A#
    			y = Cstr(Year(Now))
    			m = Cstr(Month(Now))
    			If len(m) = 1 Then	m = "0" & m
    			d = Cstr(Day(Now))
    			If len(d) = 1 Then	d = "0" & d
    		Else	'#A#
    			'=== Uses the date supplied
    			If Not IsDate(sTheDate) then 
    				Response.Write ("Not a true date format (" & sTheDate & ").")
    				Response.End
    			End if
    			d=Day(sTheDate)
    			If len(d)=1 then d= "0" & d
    			m=Month(sTheDate)
    			mi=Month(sTheDate)
    			If len(mi) = 1 Then	mi = "0" & mi
    			m=myMonth(m)			
    			y=Year(sTheDate)
    		End if	'#A#
    		Select Case iFormat
    			Case 0
    				DateFormat = d & "/" & Left(m,3) & "/" & y
    			Case 1
    				DateFormat=CLng(CDate(sTheDate))
    			Case 2
    				DateFormat = d & "/" & m & "/" & y
    			Case 3
    				DateFormat = m & ", " & d & " " & y
    			Case 4
    				DateFormat = d & " " & m & " " & y
    			Case 5
    				DateFormat = m & " " & y
    			Case 6
    				DateFormat = d & "/" & mi & "/" & y
    			Case 7
    				x=WeekDay(sTheDate)
    				dw=myDay(x)
    				DateFormat = dw & "," & d & " " & m & " " & y
    			Case Else
    				DateFormat = d & "/" & Left(m,3) & "/" & y
    		End Select
    	End Function
    Why do we exist? What is our purpose?
    >H2O Developments
    >USS Endeavour
    >Hosted@Servage

  3. #3
    SitePoint Enthusiast Northern Star's Avatar
    Join Date
    Aug 2006
    Location
    Cheshire, UK
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've always been plagued by the US/UK date format problems when writing / reading from databases... I came up with this in the end...

    Code:
    Function dbDate(dt) 
    	dbDate = year(dt) & "-" & right("0" & month(dt), 2) & "-" & right("0" & "-" & day(dt),2)
    End Function
    "If it ain't broken, don't fix it!"
    ----
    Northern Star - Web design, stategy & development.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •