---
title: "React Date & Time Credit card expiration Example | Mobiscroll"
component: "Date & Time"
framework: "React"
library_version: "6.2.0"
url: "https://demo.mobiscroll.com/react/datetime/month-year-picker"
---

# Credit card expiration - React Date & Time demo

React credit card expiration date select. Set up the date picker with month/year configuration. For React and Next.JS.

- [Live demo](https://demo.mobiscroll.com/react/datetime/month-year-picker)
- [View React JS code on GitHub](https://github.com/acidb/mobiscroll-demos-react/tree/main/src/demos/datepicker/datetime/month-year-picker)
- [View React TS code on GitHub](https://github.com/acidb/mobiscroll-demos-react-ts/tree/main/src/demos/datepicker/datetime/month-year-picker)
- This demo in other frameworks: [JavaScript](https://demo.mobiscroll.com/javascript/datetime/month-year-picker.md), [jQuery](https://demo.mobiscroll.com/jquery/datetime/month-year-picker.md), [Angular](https://demo.mobiscroll.com/angular/datetime/month-year-picker.md), [Vue](https://demo.mobiscroll.com/vue/datetime/month-year-picker.md)

## Description

Customize the wheels and format the date picker for month & year. Choose a `month/year` format for the credit card expiration date.

This and even more can be done with the [`dateWheels`](https://mobiscroll.com/docs/react/datepicker/api#localization-dateWheels) setting.

**Interested in changing the date format?** [Explore formatting options →](https://demo.mobiscroll.com/react/datetime/formatting-return-values)

## What this demo shows

- Shows a form with fields for the cardholder name, card number, expiration date, and three-digit CVV.
- **Expiration picker** Clicking the expiration field opens a wheel-style month and year picker with separate scrollable wheels for selecting the month and year. The selected values appear in the central selection area, while neighboring values are visually subdued.
- **Scrolling behavior** Users can scroll vertically through the month and year values to change the expiration date.
- **Footer actions** `Cancel` discards the change, while `Set` confirms the selected expiration date.
- **Input value** Confirming the selection displays the expiration date in the input using a `month/year` format.

## Best for

- **Credit card forms** Collecting a card expiration date as a month and year alongside the cardholder name, card number, and CVV.
- **Month and year selection** Configuring date picker wheels when a specific day is not needed.
- **Expiration date formatting** Displaying the confirmed value in a `month/year` format.

## Tutorial

```tsx
const now = new Date;
const until = new Date(now.getFullYear() + 10, now.getMonth());

<Input label="Name" placeholder="Required"/>
<Input label="Card" placeholder="Credit card number"/>
<Datepicker
    dateFormat="MM/YYYY"
    dateWheels="MMMM YYYY"
    min={now}
    max={until}
    value="12/2025"
    label="Expiration"
    placeholder="Required"
    touchUi={true}
/>
<Input label="Security" placeholder="3-digit CVV"/>
```

## API used in this demo

- [`theme`](https://mobiscroll.com/docs/react/datepicker/api#opt-theme) - option
- [`themeVariant`](https://mobiscroll.com/docs/react/datepicker/api#opt-themeVariant) - option
- [`controls`](https://mobiscroll.com/docs/react/datepicker/api#opt-controls) - option
- [`dateFormat`](https://mobiscroll.com/docs/react/datepicker/api#localization-dateFormat) - option
- [`dateWheels`](https://mobiscroll.com/docs/react/datepicker/api#localization-dateWheels) - option
- [`defaultValue`](https://mobiscroll.com/docs/react/datepicker/api#opt-defaultValue) - option
- [`min`](https://mobiscroll.com/docs/react/datepicker/api#opt-min) - option
- [`max`](https://mobiscroll.com/docs/react/datepicker/api#opt-max) - option

## Code

### JSX

```jsx
import { Datepicker, Input, Page, setOptions } from '@mobiscroll/react';

setOptions({
  theme: 'ios',
  themeVariant: 'light'
});

function App() {
  const now = new Date();
  const until = new Date(now.getFullYear() + 10, now.getMonth());

  return (
    <Page>
      <div className="mbsc-form-group">
        <div className="mbsc-form-group-title">Add a new credit card</div>
        <Input label="Name" placeholder="Required"></Input>
        <Input label="Card" placeholder="Credit card number"></Input>
        <Datepicker
          controls={['date']}
          dateFormat="MM/YYYY"
          dateWheels="MMMM YYYY"
          defaultValue="12/2025"
          min={now}
          max={until}
          label="Expiration"
          placeholder="Required"
        ></Datepicker>
        <Input label="Security" placeholder="3-digit CVV"></Input>
      </div>
    </Page>
  );
}

export default App;
```

### TSX

```tsx
import { Datepicker, Input, Page, setOptions } from '@mobiscroll/react';
import { FC } from 'react';

setOptions({
  theme: 'ios',
  themeVariant: 'light'
});

const App: FC = () => {
  const now = new Date();
  const until = new Date(now.getFullYear() + 10, now.getMonth());

  return (
    <Page>
      <div className="mbsc-form-group">
        <div className="mbsc-form-group-title">Add a new credit card</div>
        <Input label="Name" placeholder="Required"></Input>
        <Input label="Card" placeholder="Credit card number"></Input>
        <Datepicker
          controls={['date']}
          dateFormat="MM/YYYY"
          dateWheels="DD MMMM YYYY"
          min={now}
          max={until}
          value="12/2025"
          label="Expiration"
          placeholder="Required"
        ></Datepicker>
        <Input label="Security" placeholder="3-digit CVV"></Input>
      </div>
    </Page>
  );
};
export default App;
```

## Implementation notes

- A single `Datepicker` (`controls: ['date']`) is anchored to the "Expiration" input inside a plain credit-card form (`Name`, `Card`, `Expiration`, `Security` inputs); the other three inputs are plain/`mbsc-input` fields with no picker attached.
- `dateFormat: 'MM/YYYY'` controls how the confirmed value is written back into the input; `dateWheels: 'MMMM YYYY'` independently controls the format shown on the wheels themselves (full month name + year) while scrolling - the two formats are set separately and don't need to match.
- `min` is set to the current date (`now`) and `max` to ten years out, computed as `new Date(now.getFullYear() + 10, now.getMonth())` - both are dynamically calculated, not fixed dates.
- The input's initial displayed value (`12/2025`) is set as a static `value`, not derived from `min`/`max` or bound to a variable.
- The raw JS/jQuery init also sets `minWidth: 100` on the picker for layout sizing; this option is omitted from the per-framework code snippets shown to visitors but is present in the actual demo config.
- `touchUi` (true by default on touch devices) determines whether the picker renders as scroller wheels (`true`) or dropdowns/desktop rendering (`false`).

## Run it in your project

1. If not signed up yet, or don't own a license, you can [start a free trial](https://mobiscroll.com/starttrial).

2. Clone the repository:

   ```
   git clone https://github.com/acidb/mobiscroll-demos-react.git
   ```

3. If not installed yet, install the Mobiscroll CLI from NPM:

   ```
   npm install -g @mobiscroll/cli
   ```

4. Config Mobiscroll - open a terminal window in the root directory and run:

   ```
   mobiscroll config react
   ```

5. Install dependencies - open a terminal window in the root directory and run:

   ```
   npm install
   ```

6. Run the project:

   ```
   npm run dev
   ```

On a trial, add `--trial` to the config command: `mobiscroll config react --trial`.

Running a demo locally requires a Mobiscroll trial or a license; setup is per framework at https://mobiscroll.com/docs/react/getting-started/installation

## Related demos

- Previous: [Formatting values](https://demo.mobiscroll.com/react/datetime/formatting-return-values.md) - React Date & time picker with variable formats, AM/PM, 12h/24h. Inherited from localization with override possibility.
- Next: [Setting values](https://demo.mobiscroll.com/react/datetime/setting-values-defaults.md) - React Date & time picker demo with different ways to set values and defaults. Custom buttons and presets - like Now - supported.
