开发者

How to handle partial zero dates (ie. 2010-04-00) in Classic ASP/VBScript?

I have a MySQL-table in which I store, among other things, dates in a normal "date" field. Some dates however are incomplete with either the day or both the day and month missing, 开发者_开发技巧substituted with double zeroes, which I believe is the "mysql way to do it". Some examples:

2007-04-03 - 3 April 2007

2006-03-00 - Mars 2006

2008-00-00 - 2008

Only problem is, when I try to receive dates that are "incomplete" with double zeros in classic asp, it won't output it since it won't recognize it as either a date or string.

What I'd like to do is simply this, outputting the date just like a string:

Set RecSet = Connect.Execute("SELECT * FROM mytable")
    Response.Write RecSet("mydate")
Set RecSet = nothing

I know that I might solve this easily by simply changing the field from date to varchar, but I don't know if there's any side effects to this, like problems when comparing dates in varchar-fields with dates in dates-fields, or comparing varchar-dates with eachother in the SQL query.

Therefore I'd like to keep storing my dates in a date-field, but since I can't output them I have a problem.

So, anyone know how I can handle (partially) zero-dates in ASP?


You could just replace the 00s with 01s in your select statement:

SELECT REPLACE(date_column,'-00','-01') AS formatted_date
FROM mytable
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜