0

I just went all through the PHP manual and can't find what i need.

A form has a dual function where it will display dates from mySQL if they exist in US english date format m/d/y.
strftime() works fine as long as there is a date argument.
When i display the same form as a blank the default time is shown which is not desired.

How can I format a date, but force a blank for new data ?

2
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by JRM
0

I just went all through the PHP manual and can't find what i need.

A form has a dual function where it will display dates from mySQL if they exist in US english date format m/d/y.
strftime() works fine as long as there is a date argument.
When i display the same form as a blank the default time is shown which is not desired.

How can I format a date, but force a blank for new data ?

Wow! the silence is deafening!
So, there is no trick to use with an existing PHP method, then?

0

The reason for your problem isn't clear (at least to me). If you have a value from the DB then you format it. If you don't, then you make the field blank. You then use the result as a value in a type=text field and you should have the right result.

0

The reason for your problem isn't clear (at least to me). If you have a value from the DB then you format it. If you don't, then you make the field blank. You then use the result as a value in a type=text field and you should have the right result.

Thanks for the reply.
What you say is exactly what I thought would happen too.
However in my application, the form is sometimes displayed as a blank form, with the value attributes nulled . Normally, there is a pHP echo of a formatted date from a SQL query.
Nulls work for everything but the date because it it goes though
strftime().

When I display what should be null, a "todays date " is displayed.
According to the PHP manual this is default behavior for this function.
My question is if there is a way to trick it so the the default is not invoked, and I can have a blank input box.

0

I'm still missing something. If you are always displaying what is in the db and hoping that a null value in the db will be displayed as a blank when the default is to display the current local time, then I don't think you can get there from here. Check the value from the db before you get to the form and only do the strftime if there is a date. Otherwise leave it as null / blank.

0

I'm still missing something. If you are always displaying what is in the db and hoping that a null value in the db will be displayed as a blank when the default is to display the current local time, then I don't think you can get there from here. Check the value from the db before you get to the form and only do the strftime if there is a date. Otherwise leave it as null / blank.

When the form is displayed blank, there was no query done!
I null the variables. The variable is echoed in the input tags's value attribute inside of the strftime(). When this is echoed with the null , it defaults to todays date. That's the issue.

0

That's exactly it, don't do that. Don't put the strftime inside the Value. Do it all first before the form (a bit of IF - ELSE). Get the right value in a variable then use that variable in the Value.

0

That's exactly it, don't do that. Don't put the strftime inside the Value. Do it all first before the form (a bit of IF - ELSE). Get the right value in a variable then use that variable in the Value.

Yes. That's what I ended up doing. If the form was to be presented as blank, I tested for the existence of the array. If false, the variable was set to null .
If true, the variable was set to all of the strftime() business.
The input value attribute now only echoes a variable that results from the above tests.

works fine.
I am a coding minimalist. If it looks like a lot of code to do a simple thing, I try to boil it down. In this case there was no "simple trick", so it resulted in a few more lines than I though it should.
Just trying to keep things as simple as possible...
Thanks for the input.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.