Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7068269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:18:11+00:00 2026-05-28T05:18:11+00:00

In PHP if i have: $date = 2012-01-18 16:00; I can do: $newDate =

  • 0

In PHP if i have:

$date = "2012-01-18 16:00";

I can do:

$newDate = new DateTime($date);

In JS (jQuery) i have:

var date = "2012-01-18 16:00";

why i can’t:

var newDate = new Date(date);

? This return me Invalid date.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:18:12+00:00Added an answer on May 28, 2026 at 5:18 am

    In order for that string to be parsed, you need a T between the date and the time

    var date = "2012-01-18T16:00";
    var newDate = new Date(date);
    

    so to fix your original code:

    var date = "2012-01-18 16:00";
    date = date.replace(" ", "T");
    var newDate = new Date(date);
    

    DEMO


    The Date constructor will also take a year, month, and day

    var newDate = new Date(2012, 1, 18)
    

    though to get that to work you’d have to split your string up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var date = Fri Jan 29 2012 06:12:00 GMT+0100; How can i show this
I have a date in the following format MM-DD-YYYY How can I convert this
I have date in this format: 2010-01-11. I want to display JAN-11. How can
I have a date field in php which is using this code: $date =
For PHP I have a date I want line wrapped. I have $date =
In my PHP code I have a date in my variable $postedDate. Now I
i work with php/Mysql i have table with two cols (date , cash) with
I have se the below date format in the codeignitor config.php $config['log_date_format'] = 'd/m/Y';
I have a bizzare problem with php date function. code: $numDays = 8; $date
I have: <?php $file=fopen(date(Y-m-d)..txt,r+) or exit(Unable to open file!); if ($_POST[lastname] <> ) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.