欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-04-13 15:54:02
MySql中当前时间,不能直接使用Date.Now传输。猜测:这个可能跟服务器地理位置有关系;一般国外的服务器时间展示位:月/日/年; 国内通常为:年-月-日;猜测,使用的时候应注意检查 如下面的代码,可能会导致查询数据不准:应改为:Date.Now.ToString("yyyy-MM-dd HH: ......

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;
            }

 

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

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