|
|
 |
RE: FN-FORUM: ASP suckery
date posted 5th January 2007 12:32
If you response.write(oRs.Fields("daDespatchDate")) what do you get back,
check it is a valid date format.
Secondly I would personally create a function for date formatting, something
like this which is a function for format based on use depending on if using
the date in ASP or in mySQL (specifically)
Function doFormatDateTime(d, t)
if t = "SQL" then
strNewDate =Cstr(year(d))& "-" & Right(Cstr(month(d) + 100),2)& "-"
& Right(Cstr(day(d) + 100),2)
strNewTime = Right(Cstr(hour(d) + 100),2)& ":" &
Right(Cstr(minute(d) + 100),2)& ":" & Right(Cstr(second(d) + 100),2)
doFormatDateTime = strNewDate & " " & strNewTime
elseif t = "ASP" then
strNewDate = day(d) & "-" & MonthName(month(d)) & "-" & year(d)
strNewTime = Right(Cstr(hour(d) + 100),2)& ":" &
Right(Cstr(minute(d) + 100),2)& ":" & Right(Cstr(second(d) + 100),2)
doFormatDateTime = strNewDate & " " & strNewTime
end if
end function
Call using
doFormatDateTime(now(), "SQL") or doFormatDateTime(now(), "ASP")
Regards
Sam Morgan
WiredEyes
tel (Uk): +44 (0)20 7100 2178
tel (Italy): +39 070 766 242
web : www.wiredeyes.com
----
umop ap!sdn w,! aw dlaH
> -----Original Message-----
> From: [EMAIL REMOVED] [EMAIL REMOVED] On
> Behalf Of webmetric
> Sent: 05 January 2007 13:59
> To: FN-FORUM / [EMAIL REMOVED]
> Subject: FN-FORUM: ASP suckery
>
>
> I'm more of a PHP bod, but needs must and all that, so I'm
> looking at an ASP
> (classic) site for a client. I hasten to add, that I didn't
> write this site myself, and I have no idea if it's the APS
> that sucks, or the original programmer who sucks, but clearly
> something isn't right.
>
> The code is getting some data from SQL server database -
> dates in this instance.
>
> Here's the relevant code, the bits I've removed are just to
> do with the other fields that aren't relevant.
>
> szSQL = "SELECT * "
> szSQL = szSQL & "FROM SPJobs "
> szSQL = szSQL & "WHERE ( SPJobs.daCreateDate >= '" &
> Month(strFromDate) & "/" & Day(strFromDate) & "/" &
> Year(strFromDate) & " 00:00' "
> szSQL = szSQL & "AND SPJobs.daCreateDate Month(strToDate) & "/" &
> Day(strToDate) & "/" & Year(strToDate) & " 23:59' ) "
>
>
>
> szSQL = szSQL & "ORDER BY daCreateDate,SPCompanies.strCompanyName "
>
> Response.Write "SQL: " & szSQL & ""
> Set oRs = oConn.Execute( szSQL, lngRecs, adCmdText ) if
> oRs.BOF and oRs.EOF then %>
>
>
> There are no items.
>
>
> else
> oRs.MoveFirst
> Do While Not oRs.EOF
> nJobID = oRs.Fields("nJobID")
> daCreateDate = oRs.Fields("daCreateDate") daDespatchDate =
> oRs.Fields("daDespatchDate")
>
>
> strCreateDate = Day(daCreateDate) & "/" & Month(daCreateDate) & "/" &
> Year(daCreateDate)
> strDespatchDate = Day(daDespatchDate) & "/" &
> Month(daDespatchDate) & "/" &
> Year(daDespatchDate)
>
> %>
> nJobID %>
> oRs.MoveNext
> Loop
> end if
> %>
>
>
> The problem is that while daCreateDate works fine and comes
> out in the proper format. daDespatchDate always comes out as
> 30/12/1899 ( I suspect this is a default date for date
> objects ?) I note the format is correct, but the date isn't.
> Both columns do have data, both are stored as the same kind
> of date format.
>
> Any clues.
>
>
>
>
> --
> Freelancers, contractors earn more with Prosperity4 Call 0870
> 870 4414 or visit www.prosperity4.com and benefit from Inland
> Revenue approved expenses today.
>
> To advertise here: http://www.freelancers.net/advertising.html
>
> |
 |
|