check if variable value is timestamp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • theoni
    New Member
    • Feb 2008
    • 20

    check if variable value is timestamp

    Hello all,

    I am using a script to export database values to xls. I am using an if statement to check if the value is numeric and has a length of ten digits. My problem is that when I extract the valaues from the the timestamp then the phone numbers whcih are also 10 digit lenthg numbers are also covnerted to dates! the numbers may only start with 2 or 6 and have ten digits but I am not sure that if I check with preg_match whehter they begin with these two i get to extract the data appropriately. Is there any function in php that can check if a value is a timestamp?

    thank you for your help
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    What format is the timestamp?

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      If they're in a consistent format (the timestamps) then you can use a preg_match()

      Code:
      $timestamp = "2009-01-20";
      
      if (preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}/', $timestamp)) 
      {
      	// Timestamp.
      } 
      else 
      {
      	// Not a timestamp.
      }

      Comment

      • theoni
        New Member
        • Feb 2008
        • 20

        #4
        thanks!

        Originally posted by Markus
        If they're in a consistent format (the timestamps) then you can use a preg_match()

        Code:
        $timestamp = "2009-01-20";
        
        if (preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}/', $timestamp)) 
        {
        	// Timestamp.
        } 
        else 
        {
        	// Not a timestamp.
        }

        I wonder how I didn't think of that myself:(

        thank you for the help

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by theoni
          I wonder how I didn't think of that myself:(

          thank you for the help
          You're welcome.

          Mark.

          PS. Regular expressions are awful, that's why you didn't think of it :P

          Comment

          Working...