I am getting an object and I have no idea how to get the date from the datetime picker, this is my code basically:
import DateTimePicker from '@react-native-community/datetimepicker';
const [date,setDate] = React.useState(new Date())
const [today] = React.useState(new Date())
<DateTimePicker
mode='date'
// format="YYYY-MM-DD"
value={today}
display={Platform.OS === 'ios' ? 'spinner' : 'default'}
// dateFormat="day month year"
onChange={(value) => setFecha(value.event)}
minimumDate={today}
/>
When the values changes (onChange), I get:
LOG {"_dispatchInstances": {"_debugHookTypes": null, "_debugNeedsRemount": false, "_debugOwner": {"_debugHookTypes": null, "_debugNeedsRemount": false, "_debugOwner": [FiberNode], "_debugSource": undefined, "actualDuration": 1.4214559942483902, "actualStartTime": 37562183.920335, "alternate": null, "child": [Circular], "childLanes": 0, "deletions": null, "dependencies": null, "elementType": [Function Picker], "flags": 1048577, "index": 1, "key": null, "lanes": 0, "memoizedProps": [Object], "memoizedState": null, "mode": 2, "pendingProps": [Object], "ref": null, "return": [FiberNode], "selfBaseDuration": 0.1864589974284172, "sibling": null, "stateNode": null, "subtreeFlags": 0, "tag": 0, "treeBaseDuration": 0.1898289993405342, "type": [Function Picker], "updateQueue": null}, "_debugSource": undefined, "actualDuration": 1.233424998819828, "actualStartTime": 37562184.10846, "alternate": null, "child": null, "childLanes": 0, "deletions": null, "dependencies": null, "elementType": "RNDateTimePicker", "flags": 0, "index": 0, "key": null, "lanes": 0, "memoizedProps": {"accentColor": undefined, "date": 1673489495509, "displayIOS": "spinner", "enabled": true, "locale": undefined, "maximumDate": undefined, "minimumDate": 1673489495509, "minuteInterval": undefined, "mode": "date", "onChange": [Function _onChange], "onPickerDismiss": [Function onDismiss], "onResponderTerminationRequest": [Function onResponderTerminationRequest], "onStartShouldSetResponder": [Function onStartShouldSetResponder], "style": undefined, "testID": undefined, "textColor": undefined, "themeVariant": undefined, "timeZoneOffsetInMinutes": undefined}, "memoizedState": null, "mode": 2, "pendingProps": {"accentColor": undefined, "date": 1673489495509, "displayIOS": "spinner", "enabled": true, "locale": undefined, "maximumDate": undefined, "minimumDate": 1673489495509, "minuteInterval": undefined, "mode": "date", "onChange": [Function _onChange], "onPickerDismiss": [Function onDismiss], "onResponderTerminationRequest": [Function onResponderTerminationRequest], "onStartShouldSetResponder": [Function onStartShouldSetResponder], "style": undefined, "testID": undefined, "textColor": undefined, "themeVariant": undefined, "timeZoneOffsetInMinutes": undefined}, "ref": null, "return": {"_debugHookTypes": null, "_debugNeedsRemount": false, "_debugOwner": [FiberNode], "_debugSource": undefined, "actualDuration": 1.4214559942483902, "actualStartTime": 37562183.920335, "alternate": null, "child": [Circular], "childLanes": 0, "deletions": null, "dependencies": null, "elementType": [Function Picker], "flags": 1048577, "index": 1, "key": null, "lanes": 0, "memoizedProps": [Object], "memoizedState": null, "mode": 2, "pendingProps": [Object], "ref": null, "return": [FiberNode], "selfBaseDuration": 0.1864589974284172, "sibling": null, "stateNode": null, "subtreeFlags": 0, "tag": 0, "treeBaseDuration": 0.1898289993405342, "type": [Function Picker], "updateQueue": null}, "selfBaseDuration": 0.0033700019121170044, "sibling": null, "stateNode": {"_children": [Array], "_internalFiberInstanceHandleDEV": [Circular], "_nativeTag": 15355, "viewConfig": [Object]}, "subtreeFlags": 0, "tag": 5, "treeBaseDuration": 0.0033700019121170044, "type": "RNDateTimePicker", "updateQueue": null}, "_dispatchListeners": [Function _onChange], "_targetInst": {"_debugHookTypes": null, "_debugNeedsRemount": false, "_debugOwner": {"_debugHookTypes": null, "_debugNeedsRemount": false, "_debugOwner": [FiberNode], "_debugSource": undefined, "actualDuration": 1.4214559942483902, "actualStartTime": 37562183.920335, "alternate": null, "child": [Circular], "childLanes": 0, "deletions": null, "dependencies": null, "elementType": [Function Picker], "flags": 1048577, "index": 1, "key": null, "lanes": 0, "memoizedProps": [Object], "memoizedState": null, "mode": 2, "pendingProps": [Object], "ref": null, "return": [FiberNode], "selfBaseDuration": 0.1864589974284172, "sibling": null, "stateNode": null, "subtreeFlags": 0, "tag": 0, "treeBaseDuration": 0.1898289993405342, "type": [Function Picker], "updateQueue": null}, "_debugSource": undefined, "actualDuration": 1.233424998819828, "actualStartTime": 37562184.10846, "alternate": null, "child": null, "childLanes": 0, "deletions": null, "dependencies": null, "elementType": "RNDateTimePicker", "flags": 0, "index": 0, "key": null, "lanes": 0, "memoizedProps": {"accentColor": undefined, "date": 1673489495509, "displayIOS": "spinner", "enabled": true, "locale": undefined, "maximumDate": undefined, "minimumDate": 1673489495509, "minuteInterval": undefined, "mode": "date", "onChange": [Function _onChange], "onPickerDismiss": [Function onDismiss], "onResponderTerminationRequest": [Function onResponderTerminationRequest], "onStartShouldSetResponder": [Function onStartShouldSetResponder], "style": undefined, "testID": undefined, "textColor": undefined, "themeVariant": undefined, "timeZoneOffsetInMinutes": undefined}, "memoizedState": null, "mode": 2, "pendingProps": {"accentColor": undefined, "date": 1673489495509, "displayIOS": "spinner", "enabled": true, "locale": undefined, "maximumDate": undefined, "minimumDate": 1673489495509, "minuteInterval": undefined, "mode": "date", "onChange": [Function _onChange], "onPickerDismiss": [Function onDismiss], "onResponderTerminationRequest": [Function onResponderTerminationRequest], "onStartShouldSetResponder": [Function onStartShouldSetResponder], "style": undefined, "testID": undefined, "textColor": undefined, "themeVariant": undefined, "timeZoneOffsetInMinutes": undefined}, "ref": null, "return": {"_debugHookTypes": null, "_debugNeedsRemount": false, "_debugOwner": [FiberNode], "_debugSource": undefined, "actualDuration": 1.4214559942483902, "actualStartTime": 37562183.920335, "alternate": null, "child": [Circular], "childLanes": 0, "deletions": null, "dependencies": null, "elementType": [Function Picker], "flags": 1048577, "index": 1, "key": null, "lanes": 0, "memoizedProps": [Object], "memoizedState": null, "mode": 2, "pendingProps": [Object], "ref": null, "return": [FiberNode], "selfBaseDuration": 0.1864589974284172, "sibling": null, "stateNode": null, "subtreeFlags": 0, "tag": 0, "treeBaseDuration": 0.1898289993405342, "type": [Function Picker], "updateQueue": null}, "selfBaseDuration": 0.0033700019121170044, "sibling": null, "stateNode": {"_children": [Array], "_internalFiberInstanceHandleDEV": [Circular], "_nativeTag": 15355, "viewConfig": [Object]}, "subtreeFlags": 0, "tag": 5, "treeBaseDuration": 0.0033700019121170044, "type": "RNDateTimePicker", "updateQueue": null}, "bubbles": undefined, "cancelable": undefined, "currentTarget": {"_children": [], "_internalFiberInstanceHandleDEV": {"_debugHookTypes": null, "_debugNeedsRemount": false, "_debugOwner": [FiberNode], "_debugSource": undefined, "actualDuration": 1.233424998819828, "actualStartTime": 37562184.10846, "alternate": null, "child": null, "childLanes": 0, "deletions": null, "dependencies": null, "elementType": "RNDateTimePicker", "flags": 0, "index": 0, "key": null, "lanes": 0, "memoizedProps": [Object], "memoizedState": null, "mode": 2, "pendingProps": [Object], "ref": null, "return": [FiberNode], "selfBaseDuration": 0.0033700019121170044, "sibling": null, "stateNode": [Circular], "subtreeFlags": 0, "tag": 5, "treeBaseDuration": 0.0033700019121170044, "type": "RNDateTimePicker", "updateQueue": null}, "_nativeTag": 15355, "viewConfig": {"Commands": [Object], "Constants": [Object], "Manager": "RNDateTimePickerManager", "NativeProps": [Object], "baseModuleName": "RCTView", "bubblingEventTypes": [Object], "directEventTypes": [Object], "uiViewClassName": "RNDateTimePicker", "validAttributes": [Object]}}, "defaultPrevented": undefined, "dispatchConfig": {"phasedRegistrationNames": {"bubbled": "onChange", "captured": "onChangeCapture"}}, "eventPhase": undefined, "isDefaultPrevented": [Function functionThatReturnsFalse], "isPropagationStopped": [Function functionThatReturnsFalse], "isTrusted": undefined, "nativeEvent": {"target": 15355, "timestamp": 1678587095000}, "target": {"_children": [], "_internalFiberInstanceHandleDEV": {"_debugHookTypes": null, "_debugNeedsRemount": false, "_debugOwner": [FiberNode], "_debugSource": undefined, "actualDuration": 1.233424998819828, "actualStartTime": 37562184.10846, "alternate": null, "child": null, "childLanes": 0, "deletions": null, "dependencies": null, "elementType": "RNDateTimePicker", "flags": 0, "index": 0, "key": null, "lanes": 0, "memoizedProps": [Object], "memoizedState": null, "mode": 2, "pendingProps": [Object], "ref": null, "return": [FiberNode], "selfBaseDuration": 0.0033700019121170044, "sibling": null, "stateNode": [Circular], "subtreeFlags": 0, "tag": 5, "treeBaseDuration": 0.0033700019121170044, "type": "RNDateTimePicker", "updateQueue": null}, "_nativeTag": 15355, "viewConfig": {"Commands": [Object], "Constants": [Object], "Manager": "RNDateTimePickerManager", "NativeProps": [Object], "baseModuleName": "RCTView", "bubblingEventTypes": [Object], "directEventTypes": [Object], "uiViewClassName": "RNDateTimePicker", "validAttributes": [Object]}}, "timeStamp": 1673489773775, "type": "set"}
I try changing the format, but I am unable to get something like "YYYY-MM-DD" or something I can manage to set in my "date" variable using setDate and then utilize in others purposes of the app.
Any help will be very appreciated! Thank you.
What you have shown here is the Event object.
From the documentation, "It receives the event and the date as parameters." - You are most likely looking for the second parameter to retrieve the date.