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
venkatsforcevenkatsforce 

Datetime Seperation

Hi All

 

       How to seperate the Datetime as Date in one String and Time in One String?

 

Thanks

Venkatsforce

sfdcfoxsfdcfox
Use DateTime.format() to emit whatever pieces you want. See Java's SimpleDateFormat class for specifics.
Ashish_SFDCAshish_SFDC

Hi Venkat, 

 

Formula:

 

 

To split a Date/Time field into 2 separate Date and Time fields you need to create 2 Formula Fields.

 

Field 1 :  Datatype = Formula(Date)
 
DATEVALUE( CreatedDate )
 
Field 2 :  Datatype = Formula(Text)
 
MID(TEXT(CreatedDate - 0.1667), 12, 5)

  

 ***  the -0.1557 part of the formula is to convert from GMT to my Local Time.

 

To convert your Date value to a Long Date format you're going to have to create a Text field and convert each part of your Date field to Text.  Sorry i don;t have any examples of that formula, but they're available in some of the Formula Guides 

 

Apex:

 

Datetime nowTime = Datetime.now();
String DateStr = String.valueOf(nowTime.date());
String timeStr = String.valueOf(nowTime.time());

System.debug(DateStr + ' : ' + timeStr);

 

Also vote for this idea: 


https://success.salesforce.com/ideaView?id=08730000000BrUVAA0

 

Regards

Ashish

 
GlynAGlynA

Like this:

 

String theDate = String.valueOf( theDateTime.Date() );
String theTime = String.valueOf( theDateTime.Time() );

 

If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!

 

-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator