question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: value.getTime is not a function. (In 'value.getTime()', 'value.getTime' is undefined)

See original GitHub issue

👋 Hi!

Summary

You cant use the DateTimePicker with expo. When I try to open the Picker it crashes the App. I am using a Component.

Reproducible sample code

class Main extends Component {

    state = {
        activityDate: new Date(),
        showPicker: false,
        pickerValue: ""
    }

    
    render(){
        return(
            <View style={styles.container}>
                <Button 
                    title="Open"
                    onPress={() => this.setState({
                        showPicker: true
                    })}
                />

                <View>
                    { this.state.showPicker && (
                    <DateTimePicker 
                        value={this.state.showPicker}
                        mode={"date"}
                        onChange={
                            (date) => {
                                this.setState({
                                    activityDate: date,
                                    showPicker: false
                                })
                            }
                        }
                    />
                    )}
                </View>
            </View>
        )
    }    
}

const styles = StyleSheet.create({
    container: {
      flex: 1,
      backgroundColor: '#fff',
    //   alignItems: 'center',
      justifyContent: 'center',
    },
  });

  export default Main;

Steps to reproduce

  1. Start a new Expo Project
  2. Run the project with expo start or expo run:android - both fails
  3. Try to use the DateTimePicker - open it up with a Button click
  4. Basically thats it …

Describe what you expected to happen:

  1. The App crashes with the following:
  2. TypeError: value.getTime is not a function. (In ‘value.getTime()’, ‘value.getTime’ is undefined)

This error is located at: in RNDateTimePicker (created by Main) in RCTView (created by View) in View (created by Main) in RCTView (created by View) in View (created by Main) in Main (created by App) in App (created by ExpoRoot) in ExpoRoot in RCTView (created by View) in View (created by AppContainer) in RCTView (created by View) in View (created by AppContainer) in AppContainer at node_modules\react-native\Libraries\LogBox\LogBox.js:149:8 in registerError at node_modules\react-native\Libraries\LogBox\LogBox.js:60:8 in errorImpl at node_modules\react-native\Libraries\LogBox\LogBox.js:34:4 in console.error at node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error at node_modules\react-native\Libraries\Core\ExceptionsManager.js:104:6 in reportException at node_modules\react-native\Libraries\Core\ExceptionsManager.js:172:19 in handleException at node_modules\react-native\Libraries\Core\ReactFiberErrorDialog.js:43:2 in showErrorDialog at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:15792:34 in logCapturedError at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:15884:20 in update.callback at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:7199:2 in callCallback at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:7220:20 in commitUpdateQueue at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:16632:25 in commitLifeCycles at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:19216:22 in commitLayoutEffects at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:93:4 in invokeGuardedCallbackProd at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:318:2 in invokeGuardedCallback at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18952:29 in commitRootImpl at node_modules\scheduler\cjs\scheduler.development.js:468:23 in unstable_runWithPriority at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18791:17 in commitRoot at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18192:12 in performSyncWorkOnRoot at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5911:33 in runWithPriority$argument_1 at node_modules\scheduler\cjs\scheduler.development.js:468:23 in unstable_runWithPriority at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5906:23 in flushSyncCallbackQueueImpl at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5893:28 in flushSyncCallbackQueue at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18211:28 in batchedUpdates$1 at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2534:29 in batchedUpdates at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2680:16 in _receiveRootNodeIDEvent at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2800:27 in receiveTouches at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:414:4 in __callFunction at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:113:6 in __guard$argument_0 at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:365:10 in __guard at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:112:4 in callFunctionReturnFlushedQueue

TypeError: value.getTime is not a function. (In ‘value.getTime()’, ‘value.getTime’ is undefined)

This error is located at: in RNDateTimePicker (created by Main) in RCTView (created by View) in View (created by Main) in RCTView (created by View) in View (created by Main) in Main (created by App) in App (created by ExpoRoot) in ExpoRoot in RCTView (created by View) in View (created by AppContainer) in RCTView (created by View) in View (created by AppContainer) in AppContainer at node_modules\react-native\Libraries\LogBox\LogBox.js:149:8 in registerError at node_modules\react-native\Libraries\LogBox\LogBox.js:60:8 in errorImpl at node_modules\react-native\Libraries\LogBox\LogBox.js:34:4 in console.error at node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error at node_modules\react-native\Libraries\Core\ExceptionsManager.js:104:6 in reportException at node_modules\react-native\Libraries\Core\ExceptionsManager.js:172:19 in handleException at node_modules\react-native\Libraries\Core\setUpErrorHandling.js:24:6 in handleError at node_modules\expo-dev-launcher\build\DevLauncherErrorManager.js:44:19 in errorHandler at node_modules\expo-dev-launcher\build\DevLauncherErrorManager.js:49:24 in <anonymous> at node_modules\expo-error-recovery\build\ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0 at node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch at node_modules\regenerator-runtime\runtime.js:294:29 in invoke at node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch at node_modules\regenerator-runtime\runtime.js:155:27 in invoke at node_modules\regenerator-runtime\runtime.js:165:18 in PromiseImpl.resolve.then$argument_0 at node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne at node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0 at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:123:14 in _callTimer at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:177:14 in _callImmediatesPass at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:437:30 in callImmediates at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:388:6 in __callImmediates at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:132:6 in __guard$argument_0 at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:365:10 in __guard at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:131:4 in flushedQueue

Environment info

Expo Diagnostic Output:

  Expo CLI 5.2.0 environment info:
    System:
      OS: Windows 10 10.0.19043
    Binaries:
      Node: 14.17.4 - C:\Program Files\nodejs\node.EXE
      npm: 7.20.5 - C:\Dev\npm\npm\npm.CMD
    IDEs:
      Android Studio: Version     2021.1.0.0 AI-211.7628.21.2111.8139111
    npmPackages:
      expo: ~44.0.0 => 44.0.6
      react: 17.0.1 => 17.0.1
      react-dom: 17.0.1 => 17.0.1
      react-native: 0.64.3 => 0.64.3
      react-native-web: 0.17.1 => 0.17.1
    Expo Workflow: bare

npx react-native info output:

System:
    OS: Windows 10 10.0.19043
    CPU: (6) x64 Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz
    Memory: 4.23 GB / 15.94 GB
  Binaries:
    Node: 14.17.4 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 7.20.5 - C:\Dev\npm\npm\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: Version     2021.1.0.0 AI-211.7628.21.2111.8139111
    Visual Studio: Not Found
  Languages:
    Java: 1.8.0_281 - C:\Program Files\Java\jdk1.8.0_281\bin\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.1 => 17.0.1
    react-native: 0.64.3 => 0.64.3
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

datetimepicker version: “@react-native-community/datetimepicker”: “4.0.0”

iOS / Android version: Android 10

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
yesIamFadedcommented, Mar 1, 2022

It does not like new Date() it expects a ISO date but casting new Date toISOString() looks fine.

1reaction
yesIamFadedcommented, Feb 28, 2022

@Salmankhan033 Thanks, this works!

Still something that is missing is, when I set the Date it works - but opening the Picker again selects the day from today even though the new value is a state that should already be changed by the onChange Function.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DatTimePicker react-native-community, getting value.getTime ...
I'd try: value={new Date(values.date)} PS: event is also required as the ... getTime(); to const timestamp = Date.parse(value) getTime() is ...
Read more >
Value.getTime is not a function · Issue #335 - GitHub
Encountered this error value.getTime is not a function ONLY in iOS. TypeError: value.getTime is not a function at ensureNativeIsInSyncWithJS ( ...
Read more >
[Solved] TypeError: date.getTime is not a function - ItsJavaScript
The TypeError: date.getTime is not a function occurs if we call a getTime() method on the object that is not of type Date...
Read more >
value.getTime is not a function - Google Groups
Uncaught TypeError: value.getTime is not a function (anonymous function) @ lovefield.min.js:11798 rowClass.toDbPayload @ lovefield.min.js:11796
Read more >
TypeError: Date.getTime is not a Function in ... - Linux Hint
TypeError : date.getTime is not a function” occurs when getTime() method calls on non-Date object values. To fix it, simply convert date value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found