Jump to content

Recommended Posts

Posted

Boa tarde a todos

 

Tenho um problema :

 

Tenho um picker data daqui

https://bootstrap-datepicker.readthedocs.io/en/stable/options.html#quick-reference

 

quando eu clico nele com o filtro de só mostrar os meses ele devolve me o primeiro dia do mes 01-07-2018 mas queria que me devolve-se novamente para a form o nome do mes por extenso...

Alguem sabe como fazer isto...

Codigo que tenho

						<div class="col-md-4">

							<form class="form-horizontal" method='POST' action=''>
								 <div class="form-group">
									<div class="col-sm-16" >
									</br>
										<div class="input-group date datepicker-me">
											<input type="text" class="form-control" name="filtrodatadia" id="filtrodatadia" value="" placeholder="Filtrar Mês">
											<div class="input-group-addon">
												<span class="glyphicon glyphicon-th"></span>
												<button type="submit" id='search' name='search' class="btn btn-success">Ok</button>
											</div>
										</div>
										

									</div>
								 </div>
							</form>


							<script type="text/javascript">
								$(document).ready(function(){
									$('input[type="date"]').height($('input').height());
								    $('#filtrodatadia').datepicker({ 
							    		format: "yyyy-mm-dd",
									  	minViewMode: 1,
								        //todayBtn: "linked",
								        //sclearBtn: true,
								        language: "pt-BR",
								        orientation: "auto",
								        changeMonth: true,
								        //calendarWeeks: true,
								        autoclose: true,
								        todayHighlight: true,
								        disableTouchKeyboard: true,
								        toggleActive: true,
										changeMonth : true,
   										monthNamesShort: [ "J", "F", "M", "Apr", "May", "Jun", "Jul", "A", "S", "O", "N", "D" ]

								    });
								   
							    });
							</script>

							<?php 


						   if(isset($_POST['search'])){
					          $fromdate = $_POST['filtrodatadia'];
					         	$phpdate=$fromdate;


					         	function last_day_of_the_month($date = '')
								{
								    $month  = date('m', strtotime($date));
								    $year   = date('Y', strtotime($date));
								    $result = strtotime("{$year}-{$month}-01");
								    $result = strtotime('-1 second', strtotime('+1 month', $result));
								    setlocale(LC_TIME, 'pt_BR UTF-8');  
								    $monthName = date("F", mktime(0, 0, 0, $month, 10));
								    $filtrodatadia = "#filtrodatadia";
								    $filtrodatadia = $monthName;
									
								    	
								    return date('YYYY-mm-dd', $result);

								}


					         	$DataInicio = date("Y-m-d", strtotime($phpdate)); 
					          	$DataFim = last_day_of_the_month($DataInicio);


					          	//$DataFim->modify('last day of this month');


					          	// date($DataInicio;, strtotime('last day of this month', time())) ;

					          	//date("Y-m-d", strtotime('last day of this month')); 
					          	//date("Y-m-d",strtotime('last day of this month', time());
					          	//echo $DataFim;


					          	//echo $DataInicio;
					          	//echo "</br>";
					          	//echo $DataFim;

								$sqlLojaArtigos2   = "QUERY";
									
									//SERVICOS
									$sqlLojaServicos2= "QUERY";	

									
									
									//OUTROS
									$sqlLojaOutros2= "QUERY";	
									
									//DEVOLUCOES ARTIGOS
									$sqlLojaDevolucoesARTIGOS2="QUERY";
								    
									//DEVOLUCOES SERVICOS
								    $sqlLojaDevolucoesSERVICOS2="QUERY";

					          	$linhasLojaARTIGOS   = $DB2->query($sqlLojaArtigos2);
								$linhasLojaSERVICOS  = $DB2->query($sqlLojaServicos2);
								$linhasLojaOUTROS    = $DB2->query($sqlLojaOutros2);
								$linhasLojaDEVOLUCOESARTIGOS = $DB2->query($sqlLojaDevolucoesARTIGOS2);
								$linhasLojaDEVOLUCOESSERVICOS = $DB2->query($sqlLojaDevolucoesSERVICOS2);
					          }
	        				
	



							 ?>
                            </div>

						</div>	
					</div>

Obrigado

Nuno Revez

@informaster

Posted

Boas

 

Pois  até aqui está certo porque ele devolve me a data correcta ex: 2018-07-01 para julho e depois tenho uma função para meter o ultimo dia desse mês e consigo fazer o query.

 

Mas o que eu quero é que isso continue a acontecer como está mas nao mostrar na form essa data mas sim julho e em outro mes agosto... visualmente quando se clica antes de fazer ok para fazer a query.

 

Resumido: ao clicar em julho devolve para a form 2018-07-01 a unica questão é que quero que apareça ao utilizador Julho mas por tras fica mesmo essa data formatada como está

2018-07-01.

exemplo do codigo

						<div class="col-md-4">
								
                          ISTO É A FORM
							<form class="form-horizontal" method='POST' action=''>
								 <div class="form-group">
									<div class="col-sm-16" >
									</br>
										<div class="input-group date datepicker-me">
											<input type="text" class="form-control" name="filtrodatadia" id="filtrodatadia" value="" 												placeholder="Filtrar Mês">
											<div class="input-group-addon">
												<span class="glyphicon glyphicon-th"></span>
												<button type="submit" id='search' name='search' class="btn btn-success">Ok</button>
											</div>
										</div>
										

									</div>
								 </div>
							</form>
							FIM DA FORM

							PARAMETROS DO PICK DATA
  							<script type="text/javascript">
								$(document).ready(function(){
									$('input[type="date"]').height($('input').height());
								    $('#filtrodatadia').datepicker({ 
                                       O FORMATO ESTÁ CERTO
							    		format: "yyyy-mm-dd",
									  	minViewMode: 1,
								        //todayBtn: "linked",
								        //sclearBtn: true,
								        language: "pt-BR",
								        orientation: "auto",
								        changeMonth: true,
								        //calendarWeeks: true,
								        autoclose: true,
								        todayHighlight: true,
								        disableTouchKeyboard: true,
								        toggleActive: true
								        
								    });
								   
							    });


							</script>

							<?php 
					  		AQUI DEVOLVE O VALOR DA DATA FIM DEPOIS JÁ TERMOS O INICIO DO MES DIA 1
						   if(isset($_POST['search'])){
					          $fromdate = $_POST['filtrodatadia'];
					         	$phpdate=$fromdate;


					         	function last_day_of_the_month($date = '')
								{
								    $month  = date('m', strtotime($date));
								    $year   = date('Y', strtotime($date));
								    $result = strtotime("{$year}-{$month}-01");
								    $result = strtotime('-1 second', strtotime('+1 month', $result));
								    setlocale(LC_TIME, 'pt_BR UTF-8');  
								    $monthName = date("F", mktime(0, 0, 0, $month, 10));
								    $filtrodatadia = "#filtrodatadia";
								    $filtrodatadia = $monthName;


								    return date('Y-m-d', $result);
								}

								OK DATA INICIO OK E DATA FIM OK E FAZ A QUERY EM SEGUIDA E ESTA A FUNCIONAR
					         	$DataInicio = date("Y-m-d", strtotime($phpdate)); 
					          	$DataFim = last_day_of_the_month($DataInicio);

Nuno Revez

@informaster

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.