SQLite function to format numbers with leading zeroes?

This can be accomplished with a little bit of magic using string concatenation and the substr function. Long story short, here’s what you want: select substr(‘0000000000’||’1234′, -10, 10) An explanation follows. First, know that SQLite’s string concatenation operator is ||. We’ll start by taking a string that is as long as the value we want … Read more

Why does Python 3 allow “00” as a literal for 0 but not allow “01” as a literal for 1?

Per https://docs.python.org/3/reference/lexical_analysis.html#integer-literals: Integer literals are described by the following lexical definitions: integer ::= decimalinteger | octinteger | hexinteger | bininteger decimalinteger ::= nonzerodigit digit* | “0”+ nonzerodigit ::= “1”…”9″ digit ::= “0”…”9″ octinteger ::= “0” (“o” | “O”) octdigit+ hexinteger ::= “0” (“x” | “X”) hexdigit+ bininteger ::= “0” (“b” | “B”) bindigit+ octdigit ::= … Read more

How to remove leading and trailing zeros in a string? Python

What about a basic your_string.strip(“0”) to remove both trailing and leading zeros ? If you’re only interested in removing trailing zeros, use .rstrip instead (and .lstrip for only the leading ones). More info in the doc. You could use some list comprehension to get the sequences you want like so: trailing_removed = [s.rstrip(“0”) for s … Read more

How to concatenate strings with padding in sqlite

The || operator is “concatenate” – it joins together the two strings of its operands. From http://www.sqlite.org/lang_expr.html For padding, the seemingly-cheater way I’ve used is to start with your target string, say ‘0000’, concatenate ‘0000423’, then substr(result, -4, 4) for ‘0423’. Update: Looks like there is no native implementation of “lpad” or “rpad” in SQLite, … Read more

Javascript add leading zeroes to date

Try this: http://jsfiddle.net/xA5B7/ var MyDate = new Date(); var MyDateString; MyDate.setDate(MyDate.getDate() + 20); MyDateString = (‘0’ + MyDate.getDate()).slice(-2) + “https://stackoverflow.com/” + (‘0’ + (MyDate.getMonth()+1)).slice(-2) + “https://stackoverflow.com/” + MyDate.getFullYear(); EDIT: To explain, .slice(-2) gives us the last two characters of the string. So no matter what, we can add “0” to the day or month, and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)