Need date imput to be month-day-year

Need date imput to be month-day-year

Postby JohnKlassen » Mon Feb 25, 2013 7:46 am

Hi,

I have a report that prompts for a date range and then selects the correct data from #dataTable#.

Here is the code to get the date range from the form:
Code: Select all
$fromdate = reformatField($formValue['vFrom'], 11, $quotes = false);
$todate   = reformatField($formValue['vTo'], 11, $quotes = false);

I have formatted 'vFrom' and 'vto' as '13-01-2007'. Everything works with this format.

Since I live in the USA, I would like the format to be '01-13-2007'. I have tried various ways to make this work but have been unsuccessful.

Any suggestions?

John
JohnKlassen
 
Posts: 148
Joined: Wed Dec 05, 2012 1:26 pm

Re: Need date imput to be month-day-year

Postby admin » Mon Feb 25, 2013 1:30 pm

John,

What do you get just by using $formValue['vFrom']?

Steven
admin
Site Admin
 
Posts: 3081
Joined: Mon Jun 15, 2009 9:53 am

Re: Need date imput to be month-day-year

Postby JohnKlassen » Tue Feb 26, 2013 2:20 pm

Steven,

I realize now that I have 2 different issues. The first is how to display the date in month-day-year to my user. The second is how to format the same date to year-month-day in my WHERE clause.

I resolved the month-day-year display on the form by setting the format in the text tab for vFrom to '01-13-2007' and using the following"
Code: Select all
$fromdate = $formValue['vFrom'];
as you suggested.

I have not figured out how to format the date as year-month-day so I can use it with BETWEEN date ranges. I tried "
Code: Select all
$yearfromdate = date("Y-m-d", $fromdate);
but the result for '01-16-2013' came out as '1970-01-01'.

Thanks for fixing the first problem. Any suggestions for the second one?

BTW, is there any documentation for some of these commands like 'reformat' so that I know what the pareameters are doing?

Thanks,

John
JohnKlassen
 
Posts: 148
Joined: Wed Dec 05, 2012 1:26 pm

Re: Need date imput to be month-day-year

Postby admin » Tue Feb 26, 2013 3:30 pm

John,

Here's the wiki link..

http://wiki.nubuilder.com/tiki-index.php?page=Nubuilder%20PHP%20Functions%3A%20PHP%20Functions&structure=nuBuilderDocs#reformatField_

I suggest you refer to your fields with hash variables..

Code: Select all

print $formValue['vFrom'];

print '#vFrom#';  //-- use this instead



should give you - 13-01-2007

Code: Select all

$fromdate = reformatField('#vFrom#', 7);
$todate   = reformatField('#vTo#', 7);

$s = "SELECT * FROM invoice WHERE inv_date BETWEEN $fromdate AND $todate"
print $s;



should give you - SELECT * FROM invoice WHERE inv_date BETWEEN '2007-01-13' AND '2007-01-26'

Steven
admin
Site Admin
 
Posts: 3081
Joined: Mon Jun 15, 2009 9:53 am

Re: Need date imput to be month-day-year

Postby JohnKlassen » Wed Feb 27, 2013 2:01 pm

Steven,

First of all, thanks for the link to the wiki page. I had looked at it a couple of months ago and had not thought about looking there.

Secondly, thanks for pointing me in the right direction. Since I have the default format for vfrom as '01-13-2007', I had to use reformat with option 9 or 13 to get 'Y-m-d'.

The good news is that it works.

Thanks,

John
JohnKlassen
 
Posts: 148
Joined: Wed Dec 05, 2012 1:26 pm

Re: Need date imput to be month-day-year

Postby admin » Thu Feb 28, 2013 7:15 am

Excellent!
admin
Site Admin
 
Posts: 3081
Joined: Mon Jun 15, 2009 9:53 am


Return to Report Writer