SQL: Subtracting 1 day from a timestamp date

Use the INTERVAL type to it. E.g: –yesterday SELECT NOW() – INTERVAL ‘1 DAY’; –Unrelated: PostgreSQL also supports some interesting shortcuts: SELECT ‘yesterday’::TIMESTAMP, ‘tomorrow’::TIMESTAMP, ‘allballs’::TIME AS aka_midnight; You can do the following then: SELECT org_id, count(accounts) AS COUNT, ((date_at) – INTERVAL ‘1 DAY’) AS dateat FROM sourcetable WHERE date_at <= now() – INTERVAL ‘130 DAYS’ … Read more

Casting a number to a string in TypeScript

“Casting” is different than conversion. In this case, window.location.hash will auto-convert a number to a string. But to avoid a TypeScript compile error, you can do the string conversion yourself: window.location.hash = “”+page_number; window.location.hash = String(page_number); These conversions are ideal if you don’t want an error to be thrown when page_number is null or undefined. … Read more

Fastest way to convert string to integer in PHP

I’ve just set up a quick benchmarking exercise: Function time to run 1 million iterations ——————————————– (int) “123”: 0.55029 intval(“123”): 1.0115 (183%) (int) “0”: 0.42461 intval(“0”): 0.95683 (225%) (int) int: 0.1502 intval(int): 0.65716 (438%) (int) array(“a”, “b”): 0.91264 intval(array(“a”, “b”)): 1.47681 (162%) (int) “hello”: 0.42208 intval(“hello”): 0.93678 (222%) On average, calling intval() is two and … Read more

How to cast an Object to an int

If you’re sure that this object is an Integer : int i = (Integer) object; Or, starting from Java 7, you can equivalently write: int i = (int) object; Beware, it can throw a ClassCastException if your object isn’t an Integer and a NullPointerException if your object is null. This way you assume that your … Read more