:::: MENU ::::

MySQL: Select “last month” records

In order to select last month records you have to get first day of the last month and the last day of the first month. With this you use the mysql function BETWEEN.

Remember that current month could be January and the last month will in another year.

Finding first day of the last month:

DATE_FORMAT(CURRENT_DATE – INTERVAL 1 MONTH, "%Y-%m-01")

Finding the last thay of the last month:

LAST_DAY(CURRENT_DATE – INTERVAL 1 MONTH)

And the final Query is:

SELECT *
FROM `my_table`
`DATE` BETWEEN DATE_FORMAT(CURRENT_DATE – INTERVAL 1 MONTH, "%Y-%m-01") AND LAST_DAY(CURRENT_DATE – INTERVAL 1 MONTH)

How to write & (ampersand) character in Android string resource

Because ampersand or & character break the xml validation in Android string.xml file if you need to insert a text with ampersand you have to encode it like in HTML encode.

 

<string name="mystring">This is my test & example</string> <!-- this is not ok -->

correct wayWatch movie online Get Out (2017)Watch movie online The Lego Batman Movie (2017)


<string name="mystring">This is my test &amp; example</string> <!-- this is not ok -->




How to open new window with window.open and not be seen by chrome a popup

If in the command stack the window.open is not direct under the onClick event then the new window it must be a popup. If the browser is set to block popups the new window will be blocked.

Now in the WEB 2.0 world where ajax calls are a must opening a window after a success ajax call will be seen as a popup Window and Chrome will block this. Continue Reading


Android get versionCode and versionName from your AndroidManifest.xml

Sometimes showing version in your app is a good think, and when you do this a good think is to not have 2 ore more places where wou have to maintain tha app version for every releases.

In your AndroidManifest.xml there is required 2 fields

android:versionCode witch is an int with the app version

android:versionName witch is a string something like 1.0.1 showing app version.

It is recomanded to use them and do not maintain a separate constant for using it in your code. Ok so programmatically you can retrieve this fields from your AndroidManifest.xml like this:

/* Get android:versionName */
String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;

/* Get android:versionCode */
int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;

PHP: trim spaces in the middle of a string

When you let users input text in a textfield or input box it is always a good idea to use trim function to remove spaces form the beginning or the end of the string.

Today I needed a function to trim spaces from the middle of a string and replace with a single space.

/*
    this will return the string where groups of consecutive spaces
    are collapsed in a single space

    eg. $str = "This is    my test    string";
    function will output "This is my test string"
 */
function centerTrim($str){
    return preg_replace("/\s+/", " ", $str)
}

Continue Reading


MySQL: Select today, yesterday or day before yesterday records

Usually when you work with records where a date or time-stamp field is present you need to select records from:

  • today records
  • yesterday records
  • day before yesterday records

Lets say you have a table (my_table) like this:

ID Name Date
1 Jon Dow 2011-01-10
2 Jane Dow 2011-01-10

where `Date` is date type fieldWatch movie online John Wick: Chapter 2 (2017)

Today records:

SELECT *
FROM `my_table`
WHERE `Date` = CURDATE()

Continue Reading




Pages:123