SQLite julianday datetime date time zone problem small record

Source: Internet
Author: User

Busy recentlyWeibo fan genieI am very busy. I have no time to write a blog post. I want to secretly write a few lines today.

 

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.