How to solve the problem of SQLite DateTime date and time zone

Source: Internet
Author: User
Tags datetime sqlite

The commonly used DateDiff function in MSSQL returns the number of days difference between two days. In SQLite, there is a function julianday, which can be replaced.

 

The usage is: julianday (datetime ()-julianday (CreateTime) -- CreateTime is the column name.

 

It has always been used in this way. It is a bit necessary today. The same click is valid for one day. It is written as: where julianday (datetime ()-julianday (CreateTime) = 0.

 

After debugging, I found several errors.

 

1: The difference between julianday (datetime ()-julianday (CreateTime) is not an integer, it is a floating point, so it is not equal to 0.

Datediff (d, getdate (), '2017-10-13 11:11:11 ') is an integer, which is a difference.

 

2: datetime (). The default value is UTC time, which is the time difference between it and our default time. Just change it to datetime ('Now ', 'localtime.

 

Therefore, the correct syntax is: where julianday (datetime ('Now ', 'localtime')-julianday (CreateTime) <1

 

OK. This is a small record here.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.