You need to sign in to do that
Don't have an account?

error in comparing date values(in text ) in salesforce
I am converting the date values to string and then using them but whn i use a '<' or '>' operator it gives an error .
so i need to reconvert date1 and sofi variables in date again so that i can use them with < and > operators.. can anyone tell me how to do it??
my code is:
<div style="margin-top:3px;margin-left:3px;z-index:1">
<apex:variable var="date1" value="{!TEXT((MOD(FLOOR( (wk.startingdate-7-DATEVALUE("2007-01-01" ))/7),52))+1)}"/>
<apex:variable var="sofi" value="{!TEXT((MOD(FLOOR( (t.SOFI__c-7-DATEVALUE("2007-01-01" ))/7),52))+1)}"/>
<apex:outputPanel rendered="{!IF(date1=sofi,true,false)}">
<a class="{!IF(date1< sofi,'red','')}" style="hover:text-decoration:none;" href="/{!t.Id}" title="{!d}: PT System '{!t.Name}' for '{!t.Owner.Name}'" target="blank">_____</a> <font size="+1"></font>
</apex:outputPanel>
</div>
so i need to reconvert date1 and sofi variables in date again so that i can use them with < and > operators.. can anyone tell me how to do it??
my code is:
<div style="margin-top:3px;margin-left:3px;z-index:1">
<apex:variable var="date1" value="{!TEXT((MOD(FLOOR( (wk.startingdate-7-DATEVALUE("2007-01-01" ))/7),52))+1)}"/>
<apex:variable var="sofi" value="{!TEXT((MOD(FLOOR( (t.SOFI__c-7-DATEVALUE("2007-01-01" ))/7),52))+1)}"/>
<apex:outputPanel rendered="{!IF(date1=sofi,true,false)}">
<a class="{!IF(date1< sofi,'red','')}" style="hover:text-decoration:none;" href="/{!t.Id}" title="{!d}: PT System '{!t.Name}' for '{!t.Owner.Name}'" target="blank">_____</a> <font size="+1"></font>
</apex:outputPanel>
</div>
You can use any of the below code to convert into date
1.Datetime st = Datetime.parse('11/20/2010 12:00:00 PM');
2.private Date setStringToDateFormat(String myDate) {
String[] myDateOnly = myDate.split(' ');
String[] strDate = myDateOnly[0].split('/');
Integer myIntDate = integer.valueOf(strDate[1]);
Integer myIntMonth = integer.valueOf(strDate[0]);
Integer myIntYear = integer.valueOf(strDate[2]);
Date d = Date.newInstance(myIntYear, myIntMonth, myIntDate);
return d;
}
If this answers your question please mark it as solution(BestAnswer)
Thanks and Regards
sandhya
I am trying to pass values of date1 and sofi in the code to the controller but it is giving null... can you take a look at my code..
<div style="margin-top:3px;margin-left:3px;z-index:1">
<apex:variable var="date1" value="{!TEXT((MOD(FLOOR( (wk.startingdate-7-DATEVALUE("2007-01-01" ))/7),52))+1)}"/>
<apex:variable var="sofi" value="{!TEXT((MOD(FLOOR( (t.SOFI__c-7-DATEVALUE("2007-01-01" ))/7),52))+1)}"/>
<apex:outputPanel rendered="{!IF(date1=sofi,true,false)}
<a class="{!IF(date1=sofi,'red','')}" style="hover:text-decoration:none;" href="/{!t.Id}" title="{!d}: PT System '{!t.Name}' for '{!t.Owner.Name}'" target="blank">_____</a> <font size="+1"></font>
<apex:param name="sofi" value="{!TEXT((MOD(FLOOR( (wk.startingdate-7-DATEVALUE("2007-01-01" ))/7),52))+1)}" assignTo="{!sofi}"/>
<apex:param name="date1" value="{!TEXT((MOD(FLOOR( (wk.startingdate-7-DATEVALUE("2007-01-01"))/7),52))+1)}" assignTo="{!date1}"/>
</apex:outputPanel>
</div>
can you post your controller code.
Thanks and Regards
sandhya
vf block
<div style="margin-top:3px;margin-left:3px;z-index:1;text-decoration:none;">
<apex:outputPanel rendered="{!IF(t.SOP__c = day.date,true,false)}">
<a class="{!IF(t.SOP__c = day.date, 'blue','')}" href="/{!t.Id}" title="{!d}: PT System '{!t.Name}' for '{!t.Owner.Name}'" target="blank">_____</a> <font size="+1"></font>
</apex:outputPanel>
</div>
<div style="margin-top:3px;margin-left:3px;z-index:1">
<apex:variable var="date1" value="{!TEXT((MOD(FLOOR( (wk.startingdate-7-DATEVALUE("2007-01-01" ))/7),52))+1)}"/>
<apex:variable var="sofi" value="{!TEXT((MOD(FLOOR( (t.SOFI__c-7-DATEVALUE("2007-01-01" ))/7),52))+1)}"/>
<apex:outputPanel rendered="{!IF(date1=sofi,true,false)}">
<a class="{!IF(date1=sofi,'red','')}" style="hover:text-decoration:none;" href="/{!t.Id}" title="{!d}: PT System '{!t.Name}' for '{!t.Owner.Name}'" target="blank">_____</a> <font size="+1"></font>
<apex:param name="sofi" value="{!TEXT((MOD(FLOOR( (wk.startingdate-7-DATEVALUE("2007-01-01" ))/7),52))+1)}" assignTo="{!sofi}"/>
<apex:param name="date1" value="{!TEXT((MOD(FLOOR( (wk.startingdate-7-DATEVALUE("2007-01-01"))/7),52))+1)}" assignTo="{!date1}"/>
</apex:outputPanel>
</div>
<div style="margin-top:3px;margin-left:3px;z-index:1">
<apex:variable var="date1" value="{!TEXT((MOD(FLOOR( (wk.startingdate-7-DATEVALUE("2007-01-01" ))/7),52))+1)}"/>
<apex:variable var="Confirmeddeliverydate" value="{!TEXT((MOD(FLOOR( (t.Confirmed_delivery_date__c-7-DATEVALUE("2007-01-01" ))/7),52))+1)}"/>
<apex:outputPanel rendered="{!IF(date1=Confirmeddeliverydate,true,false)}">
<a class="{!IF(date1=Confirmeddeliverydate,'xyx','')}" style="hover:text-decoration:none;background:white; !important" href="/{!t.Id}" title="{!d}: PT System '{!t.Name}' for '{!t.Owner.Name}'" target="blank"></a> X <font size="+1"></font>
</apex:outputPanel>
</div>
public with sharing class ProjectCalContrlerTrial {
/*-------------------Begins Variable Declaration----------------------------*/
public Date startDate{get;set;}
public Date endDate{get;set;}
public Date startDate1{get;set;}
public Date endDate1{get;set;}
public String sofi{get;set;}
public String date1{get;set;}
public String date2{get;set;}
private Month month;
public Project_Line_Item__c LineItem {get;set;}
private List<Project_Line_Item__c> foundRentals;
private Set<Id>rentIds = new Set<Id>();
private List<Project_Line_Item__c> Items = new List<Project_Line_Item__c>();
private Integer enteredCount;
private List<PT_System__c > rent_spec = new List<PT_System__c >();
public boolean displaySearchFields{get;set;}
public String region = UserInfo.getLocale();
public boolean weeklyView{get;set;}
public Integer MonthsBetween{get;set;}
public boolean forceWeeklyView{get;set;}
public boolean headlessMode{get;set;}
private String Filename;
private String Projectname;
private String Username;
/*--------------------Ends Variable Declaration------------------------------*/
public ProjectCalContrlerTrial (ApexPages.StandardController LabCtrler)
{
System.debug('******************** Date Value *******************'+date11);
System.debug('*********************** Sofi Value ****************'+sofi1);
System.debug('***************************************'+date1);
System.debug('***************************************'+sofi);
System.debug('***************************************'+date2);
Filename = 'ProjectCalendar';
LineItem = new Project_Line_Item__c();
startDate = date.today().toStartofMonth();
endDate = startDate.addMonths(1);
displaySearchFields = true;
weeklyView = false;
Date d = system.today();
setMonth(d);
forceWeeklyView = false;
String proj = ApexPages.currentPage().getParameters().get('proj');
Id projId = LabCtrler.getId();
if(proj != null || projId != null)
{
if(projId != null) {
LineItem.Name= projId;
headlessMode = true;
} else {
LineItem.Name= proj;
headlessMode = false;
}
headlessMode = false;
}
}
//-----------------getWeeks-------------------
public List<Month.Week> getWeeks()
{
return month.getWeeks();
}
//-----------------getMonth-------------------
public Month getMonth()
{
return month;
}
//---------------setMonth---------------------
private void setMonth(Date d)
{
month = new Month(d);
}
//---------------setTimeSpan---------------------
private void setTimeSpan(Date StartDate, Date Enddate)
{
month.Timespan(StartDate, EndDate);
}
//---------------getVerleih---------------------
public List<PT_System__c> getVerleih()
{
Date nextMonth = month.getFirstDate().addDays(36);
Date prevMonth = month.getFirstDate().addDays(-6);
//---------------SORTING ON DATE FIELD (SOP__c)---------------
rent_spec = [Select Id, Name, Owner.Name, SOP__c,SOFI__c,Confirmed_delivery_date__c From PT_System__c WHERE SOP__c >=:startDate AND SOP__c <=:endDate+1 order by SOP__c asc];
return rent_spec;
}
//---------------getRegion---------------------
public String getRegion()
{
return region;
}
//---------------PageReference page1------------
public PageReference page1() {
clear();
Items.clear();
rentIds.clear();
return Page.PTSystemCal;
}
//---------------PageReference page2------------
public PageReference page2(){
startDate = startDate1;
endDate = endDate1;
setMonth(startDate);
setTimeSpan(startDate, endDate);
if(forceWeeklyView == true || startDate.monthsBetween(endDate) >=3)
{
weeklyView = true;
}
else if(forceWeeklyView == false)
{
weeklyView = false;
}
//getVerleih();
displaySearchFields = false;
return Page.PTSystemClender;
}
//---------------PageReference refilter------------
public PageReference refilter(){
setMonth(startDate);
setTimeSpan(startDate, endDate);
System.debug('*******************date1*******************'+date1);
System.debug('********************sofi******************'+sofi);
System.debug('***************************************'+date2);
if(forceWeeklyView == true || startDate.monthsBetween(endDate) >=3)
{
weeklyView = true;
}
else if(forceWeeklyView == false)
{
weeklyView = false;
}
system.debug('Page2()) Filter criteria: '+LineItem);
return null;
}
//---------------getFilename --------------
public String getFilename ()
{
Filename = 'ProjectCalendar';
if(LineItem.Lab_R_D__c != null)
{
Filename = getProjectname();
}
if(LineItem.Start_Date__c != null)
{
Filename += '_'+LineItem.Start_Date__c.year()+'-'+LineItem.Start_Date__c.month()+'-'+LineItem.Start_Date__c.day();
}
if(LineItem.End_Date__c != null)
{
Filename += '--'+LineItem.End_Date__c.year()+'-'+LineItem.End_Date__c.month()+'-'+LineItem.End_Date__c.day();
}
if(LineItem.Responsible_User__c != null)
{
Filename += '_'+getUsername();
}
Filename += '.xls';
return Filename;
}
//---------------getUsername -------------
public String getUsername()
{
if(LineItem.Responsible_User__c != null)
{
User u = [SELECT Firstname, Lastname FROM User WHERE ID = :LineItem.Responsible_User__c];
return u.Firstname+'_'+u.Lastname;
}
else
{
return '';
}
}
//---------------getProjectname-------------
public String getProjectname()
{
if(LineItem.Lab_R_D__c != null)
{
return [SELECT Project_name__c FROM Lab__c WHERE ID = :LineItem.Lab_R_D__c].Project_name__c;
}
else
{
return '';
}
}
//---------------clear -----------------
public void clear()
{
startDate = date.today().toStartofMonth();
endDate = date.today().toStartofMonth().addMonths(1);
}
}
try to print startingdate and see if you have value in that
Thanks and Regards
sandhya