Results 1 to 4 of 4

Thread: Browser JS timestamp compatibility when testing against database timestamp

  1. #1
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default Browser JS timestamp compatibility when testing against database timestamp

    Hi All,
    I'm having a difficult time understanding why browsers don't accept "-" in a timestamp (http://dygraphs.com/date-formats.html). I'm wondering if anyone has a solution for testing mysql database timestamps in javascript, considering the recommendation for javascript dates is to use "/" and the database timestamps "-".
    Last edited by crobinson42; 12-18-2013 at 10:54 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,004
    Thanks
    44
    Thanked 3,203 Times in 3,165 Posts
    Blog Entries
    12

    Default

    I think some browsers accept - as a separator in a timestamp that's a string (if it were numbers, that would be a minus sign). I believe the comma is the only acceptable separator for timestamps composed of 2 or more numbers. The slash / is more common for a string. But you have to be sure it's a string. Otherwise / is division.

    Always bear in mind that generally there's less type conversion in javascript than in PHP. And that for things like dates and times, things are a little more limited than with PHP. That said, a timestamp from one can easily be converted and/or compared with a timestamp from the other.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    crobinson42 (12-16-2013)

  4. #3
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default

    Thanks for the info John. Here's the simple solution to my problem is was having in case a newbie runs into the problem:

    Code:
    var unixTimestamp = '2014-12-10 09:10:05';
    var unixTime = new Date(unixTimestamp*1000); //convert the unix timestamp into milliseconds
    var currentTime = new Date(); //gets current timestamp in milliseconds
    
    //test timestamps
    
    if ( unixTime > currentTime){
    
    } 
    else if ( unixTime < currentTime ){
    
    }......etc.

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,004
    Thanks
    44
    Thanked 3,203 Times in 3,165 Posts
    Blog Entries
    12

    Default

    That doesn't look quite right to me. But I'll take your word for it. There are several ways. And it is correct that a pure numeric UNIX time stamp with no separators (like: 1387414696) multiplied by 1000 is equivalent to a javascript one.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. convert unix timestamp to date php
    By TwitterRooms in forum PHP
    Replies: 4
    Last Post: 01-26-2012, 08:40 PM
  2. Automatic TimeStamp Actions
    By Techykid3 in forum MySQL and other databases
    Replies: 20
    Last Post: 09-01-2011, 08:33 PM
  3. how to display MySQL timestamp?
    By jr_yeo in forum MySQL and other databases
    Replies: 15
    Last Post: 02-01-2009, 06:33 PM
  4. MySQL Timestamp into PHP Format
    By cancer10 in forum PHP
    Replies: 1
    Last Post: 03-17-2008, 03:43 AM
  5. how to edit timestamp entries
    By blwow in forum PHP
    Replies: 5
    Last Post: 05-06-2007, 08:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •