How to set Android DatePicker to start from today’s date

If you are planning to use a DatePicker in your android project and you want to set the DatePicker dialog date to start from today’s date. In that case, you don’t want your users to select any date that is below today’s date then this solution might work for you.

To create a new android application project, following the steps as stipulated below.

Go to File menu

Click on New menu

Click on Android Application

Enter Project name: AndroidSetDatePickerTime

Package: com.inducesmile.androidsetdatepickertime

Select Empty Activity

Keep other default selections

Continue to click on next button until Finish button is active, then click on Finish Button.

If you are using Android Studio as your choice IDE, the new project will create a default

activity file and its corresponding layout file.

Open your default layout file, copy and paste the code below to the file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""


We have added a button click so that when the button get clicked, it will pop-up our DatePicker dialog. Users can then select the date they want to use.

Now, open the activity class and paste the following code.

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
public class MainActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        Button mButton = (Button)findViewById(;
        mButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                DatePickerDialog mDate = new DatePickerDialog(MainActivity.this, date, 2016, 2, 24);
                mDate.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
    final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            view.setMinDate(System.currentTimeMillis() - 1000);

If you have a question or any code snippet you are looking for, you can use the comment box below to drop a line.

Add a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

50% Discounts On Projects

Do you have a custom project with a clear requirements, we are currently giving a 50% discount on all projects.

We will work with you to ensure we deliver what you need.

If you have questions or want to chat with us, you can reach us on Skype (henry.tochi)

Languages and technologies we use - Java, Kotlin, Laravel, Vue, React, Flutter, Swift and more.