1

it's amzing when i send a null value in date() as a second parameter then it returns some time? how to remove this thing. i want that if a string is null or empty then doesn't do anything

    $x=strtotime();
    var_dump($x);
    var_dump($x==NULL);
    echo date('H:i',$x);

display

 Warning: strtotime() expects at least 1 parameter, 0 given in 
 D:\xampp\htdocs\test\index.php on line 1
 bool(false) bool(true) 05:30

3 Answers 3

1

It makes perfect sense. NULL equals 0 in this case. date() counts from 0, which was January 1st, 1970, 0:00:00 UTC.

You are based in Jaipur. Your timezone is UTC + 5:30 hours. Thus, date(0) on your server, in your time zone, will result in January 1st, 1970, 5:30.

Sign up to request clarification or add additional context in comments.

Comments

1

Why not check the value of $x?

if($x != NULL)
    echo date('H:i',$x);

3 Comments

I M USING date() in mysql query, how can i do this inside mysql query
Do your check before executing the query?
no, actually i m inserting like insert into tbl_x(rank,open_time) in values('1',date('H:i',$x)),('2',date('H:i',$y)),('3',date('H:i',$z)); where open_time is time type field in mysql and $y and $z have some value
1

The second parameter to the date() function is optional: if it's not provided, date() uses the current time. If you want to prevent this you have to check your variable before calling it, or write a wrapper function and use that instead of date().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.