DatePicker is UI (User Interface) Element in android That allows user to select a date by day, month and year. DatePicker is subclass of FrameLayout Class in Android. To Create DatePicker In Android We Use <DatePicker> Tag in XML And You can also create DatePicker Programmatically

Table of Contents

Important DatePicker Attributes

Attribute Description
android:datePickerMode
To set date picker in the mode of either calendar or in spinner we use this attribute

If you set datePickerMode=”calendar”
Your DatePicker will look like this

DatePicker in Android

If you set datePickerMode=”spinner”
Your DatePicker will look like this

DatePicker in Android Spinner Mode

If you want to create DatePicker in calendar mode, Then In your XML file Inside your <DatePicker> Tag You can set android:datePickerMode to Calendar or you can set this attribute to spinner in order to use DatePicker in spinner mode. According to your need you can use both this mode inside your app. 

Important DatePicker Methods

Attribute Description
getYear()
To get Selected Year
getMonth()
To get Selected Month
getDayOfMonth()
To get Selected Day Of Month
getFirstDayOfWeek()
This Method returns first day of the week
updateDate(int year, int month, int dayOfMonth)
To Update The current date

DatePicker Example

Here is an example Demonstrating How to Use DatePicker. 

File : activity_main.xml


Activity Class 
File : MainActivity.java

If you find this content Helpful feel free to Enroll in our Android Development Course with Kotlin contact us for more information 

If you liked this article, then share it with your friends.

Related Tutorials

Anatomy of an android app
Anatomy of an Android App
  • July 18, 2025
  • Com 0

Anatomy of an Android App Anatomy of an Android app refers to its core structure and essential components that work…

Roomdatabase in android image
Mastering room database using kotlin: Complete Guide with CRUD Operations
  • April 4, 2025
  • Com 0

Local data storage is essential for building modern Android apps that work offline and store data persistently. Whether you’re creating…

Android SDK Image
Android SDK and It’s Components
  • March 27, 2025
  • Com 0

Android SDK stands for Android Software Development Kit which is developed by Google for Android Platform with the help of…

Android Architecture Image
Android Architecture
  • March 20, 2025
  • Com 0

Android architecture is the foundation and structure that makes an Android device work. Android architecture consists of layers that work together to run apps…

Content Provider in Android Feature Image
Content Provider in Android
  • February 7, 2025
  • Com 0

Content Provider in Android is a component of the Android application that is useful for sharing data with other apps.…

SQLite Database in Android
SQLite Database in Android
  • January 28, 2025
  • Com 0

Android app or any application is made of two things Data And Functionality. So In Any application we need a…

Get Your Free Java
Data Structures Cheat Sheet! 🎁

Download the ultimate cheat sheet covering the Top 10 Data Structures every Java developer must know — with real-life examples! Just enter your email and get the free pdf.

We respect your privacy. No spam. Read our privacy policy for more information.