Hi i am using ionic 5 for my project and recently migrated to ionic 6 everything looks great but one thing concerns me is the datetime picker i want that in old style this way please help!
-
Plz share some code... – mahen23 Jan 19 '22 at 08:01
-
plz check my code in my git https://github.com/sai7135/ionic6.git fork it make changes and re comment your git if possible – sai kiran Jan 22 '22 at 10:58
4 Answers
You can do it using some hacking. The ion-datetime
accepts a property named yearValues
where you can create 'custom' year values.
html
:
<div class="hacking-datetime">
<ion-datetime presentation="year" [yearValues]="yearValues"></ion-datetime>
<ion-datetime presentation="month-year"></ion-datetime>
</div>
ts
:
yearValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30];
css
:
.hacking-datetime {
display: grid;
grid-template-columns: 1fr 2fr;
position: absolute;
bottom: 0;
width: 100%;
}
Although it will be visually the same as before(after some css of course) programatically you'll have to do a lot of work. And, as I said before it's a hack, so I really do not reccomend you using it :-)

- 124
- 1
- 5
-
-
-
You get the values of both ion-datetime and use the Date class or date-fns to combine them into one date – Josemar Silva Feb 08 '22 at 16:03
EDIT: From my understanding there is no way to use the old style UI. See more here: Use ion-datetime v4 instead of v6
I think your best bet is to use the new ion-date and try to implement your old style using CSS/modal properties. You might try something like this:
<ion-button id="open-modal">Open Datetime Modal</ion-button>
<ion-modal
[initialBreakpoint]="0.5" trigger="open-modal">
<ng-template>
<ion-content>
<ion-datetime></ion-datetime>
</ion-content>
</ng-template>
</ion-modal>
Here you can find more examples of how to use the new date-picker: https://ionicframework.com/docs/api/datetime#usage
And here you can find more info about styling/ using the modal: https://ionicframework.com/docs/api/modal#inline-modal

- 1,179
- 1
- 7
- 18
-
no bro i only need cylindrical datetime picker the one i showd you in the image i have no choise need to use ionic 6 only – sai kiran Jan 25 '22 at 09:06
-
can you please implement datetime on ion-picker and send me the git repo? ion picker looks like the one in ionic5 datetime – sai kiran Jan 25 '22 at 09:09
-
@saikiran do you know if the ionic5 picker scroll with the mouse on the desktop? – Paranoid Android Mar 10 '22 at 09:27
-
You can use this way
<ion-datetime showDefaultButtons="true" presentation="date" #popoverDatetime1 (ionChange)="setPreferredDate(popoverDatetime1.value)" > </ion-datetime>
setPreferredDate(value) {
const convertDate = format(parseISO(value), 'dd MMM , yyyy');
this.schedulePreferredDate = convertDate;
}
https://ionicframework.com/blog/the-new-datetime-component-in-ionic/

- 2,703
- 2
- 24
- 29
<ion-datetime presentation="date" [preferWheel]="true"></ion-datetime>
This works for me, shows a date spinner with month / day / year wheels

- 10,559
- 3
- 54
- 60