function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
astroastro 

How to print today's date in visualforce?

I know this is probably a silly question but I'm new to web programming and salesforce/apex/vf and I need to do this but cannot find a way.

 

I need to be able to simply print today's date on a page.  I've tried embedding some javascript in <script></script> tags and that does not seem to do anything at all.

 

Thank's to all that read 

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert

Try this snippet out. Shows example of a few Date related expressions:

 

 

<apex:page > Today's full date is: {!TODAY()}<br/> Today's Month is: {!MONTH(TODAY())}<br/> Number Day of the Month: {!DAY(TODAY())}<br/> Current Year: {!YEAR(TODAY())}<br/> </apex:page>

 

 

 

All Answers

aalbertaalbert

Try this snippet out. Shows example of a few Date related expressions:

 

 

<apex:page > Today's full date is: {!TODAY()}<br/> Today's Month is: {!MONTH(TODAY())}<br/> Number Day of the Month: {!DAY(TODAY())}<br/> Current Year: {!YEAR(TODAY())}<br/> </apex:page>

 

 

 

This was selected as the best answer
astroastro

Thank you very much aalbert i did not know you could call those functions directly within visualforce!

 

I appreciate you responding, it was a big help.

 

Thank's again! 

SteveAnderson41SteveAnderson41

Use the today() or now() expression language function, ie,

 

<apex:page>

{!today()}

</apex:page>

 

See the "Operators and Functions" topic in the online help for more similar expression language information.

 

 

astroastro

thank's for that.  I didn't realize I could use those operators and functions in that way within vf.  Oh, silly me.

 

Thank you for sharing that.

myntra flipkartmyntra flipkart
Guys it is showing in GMT but I want to show according to the users time zone then what should I write??
David Roberts 4David Roberts 4


This is GMT formmated date/time:
<apex:outputText value="{0, date, EEE, MMM d, yyyy, HH:mm:ss z}">
        <apex:param value="{!NOW()}" /> 
</apex:outputText>
Or
<apex:outputText value="{!NOW()}"/>

To get the local time zone, insert a space before the left brace..
<apex:outputText value=" {!NOW()}"/>