当前位置: 移动技术网 > IT编程>数据库>Mysql > Mysql语句中当前时间不能直接使用Date.Now传输

Mysql语句中当前时间不能直接使用Date.Now传输

2019年02月27日  | 移动技术网IT编程  | 我要评论

mysql中当前时间,不能直接使用date.now传输。猜测:这个可能跟服务器地理位置有关系;一般国外的服务器时间展示位:月/日/年; 国内通常为:年-月-日;猜测,使用的时候应注意检查

如下面的代码,可能会导致查询数据不准:应改为:date.now.tostring("yyyy-mm-dd hh:mm")

/// <summary>
            /// (用户id) => 用户优惠码可用数量
            /// </summary>
            /// <param name="userid">用户id</param>
            /// <returns></returns>
            public static int getcouponcount(int userid)
            {
                int count = 0;
                if (userid > 0)
                {
                    list<string> wherelist = new list<string>
                    {
                        string.format("`{0}` = '{1}'", coupon_user_mapping._userid_, userid),
                        string.format("`{0}` = '{1}'", coupon_user_mapping._status_, ecoupon.status.可用.getvalue()),
                        string.format("`{0}` > '{1}'", coupon_user_mapping._useendtime_, datetime.now)
                    };
                    string where = string.join(" and ", wherelist);
                    wherelist.clear();
                    wherelist = null;
                    coupon_user_mappingbll.select(where, out count);
                }
                return count;
            }

 

下面是本公司服务器时间测试截图:

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网