Hot answers tagged

8

You don't need to use SOQL. You can just create a new DateTime and set it to the current date and time like below DateTime myDateTime = system.now(); Or if you only want the date, then Date myDate = system.today();


6

You can use <apex:actionPoller/> to implement your requirement Visualforce <apex:page controller="autoSaveController"> <apex:form id="form1"> <apex:actionPoller action="{!save}" rerender="form1" interval="300"/> <apex:commandButton value="save" action="{!save}"/> </apex:form> </apex:page> In the save() method in ...


6

There is a Time Class in Apex that you can use. See my example below for how to get the current time displayed in the HTML 5 time input field Controller: public class MyTimeController { public Time myTime { get { if (myTime == null) { myTime = DateTime.now().time(); } return myTime; ...


5

This code will get you the local time for the logged in user, by leveraging the timezone offset to subtract/add from GMT. It's even smart enough to account for Daylight Saving. TimeZone tz = UserInfo.getTimeZone(); DateTime dt = Datetime.now(); system.debug('Actual Time as String ' + dt.format()); system.debug('Offset ' + tz.getOffset(dt)/1000); system....


5

DateTime values are represented by an epoch time in GMT, and converted to the appropriate date/time when requested via the appropriate methods. System.debug, coincidentally, always displays GMT. Try this: DateTime now = DateTime.now(); Integer hours = now.hour(), minutes = now.minute(), seconds = now.second(); System.debug(now); System.debug(hours+':'+...


5

The closest you can get to this is by using the FormatDate AMPscript function with ISO pattern: set @dateString = "9/14/2019 4:37:57 PM" set @dateISO = FormatDate(@dateString,"iso") %%=v(@dateISO)=%% outputs: 2019-09-14T16:37:57.0000000 You can then format this further using Replace and Substring functions: set @dateString = "9/14/2019 4:37:57 PM" set @...


4

Alternatively, there is a method System.currentTimeMillis() that returns the current time in milliseconds. From that, you can create a new DateTime with the DateTime.newInstance(Long) method: Long longtime = System.currenTimeMillis(); DateTime dt = DateTime.newInstance(longtime);


4

DateTime usually shows the time in GMT. Format function retrieves the time based on user's timezone defined in Salesforce. Let's say, this timezone is CST. So, format() or formatLong() (Converts the date to the local time zone and returns the converted date in long date format.) returns CST time. System.debug('current time=' + System.Now().format()); Now ...


4

You can use the Formatted Date Time <lightning:formattedDateTime> or Formatted Time <lightning:formattedTime> component to display a formatted time value. Your Code using the Formatted Time component would be as below. <td data-label=""> <div class="slds-truncate" title=""> <lightning:formattedTime value="{!...


4

The Time field type was created specifically to have a field that would be a time value independent of date. If your business hours are 08:00 - 18:00, regardless of the date, let's say, this is the purpose of this field. As the help states it is used "for time management, event planning, and project management." For times that are time-zone dependent you ...


3

A quick Google revealed this: CASE( MOD(TODAY() - DATE(1900, 1, 8), 7), 0, TODAY() + 7, 1, TODAY() + 6, 2, TODAY() + 5, 3, TODAY() + 4, 4, TODAY() + 3, 5, TODAY() + 2, 6, TODAY() + 1, DATE(9999,01,01) ) that I assume could be refactored a bit and changed for your case to: CloseDate + CASE( MOD(CloseDate - DATE(1900, 1, 8), 7), 0, 7, 1, 6, 2, 5, 3, 4, 4, ...


3

Try: DateTime dt = DateTime.newInstance(system.currentTimeMillis()); system.debug(dt.format('yyyy-MM-dd\'T\'hh:mm:ss\'z\')); Ofcourse, you can change the options under datetime format method to the way you like.


3

The value in parenthesis appears to be epoch seconds, that is, seconds since 12:00 AM Jan 1, 1970, and the value after the + sign looks like a timezone offset. We can convert epoch seconds to a Datetime using Datetime.newInstance(Long seconds), and just take the date part from the result. This method expects a GMT value, which is what the portion before ...


3

You can use the Datetime type here despite your comments to the contrary. If you need a List<Time>, you can call time() on each instance (similar to date(), year(), etc.). Datetime pointer, max; pointer = Datetime.newInstance(Date.today(), objAvailableTime.StartTime); max = (objAvailableTime.EndTime < objAvailableTime.StartTime) ? Date....


3

TimeNow() returns the current time in GMT. When the user views a Time field it's converted to their local timezone, but the value in the field is also always stored as GMT. The almost-84 million number you're getting is the result of subtracting a later timevalue from an earlier one - rather than give a negative number, the system appears to calculate it ...


2

As you have noticed there isn't much built in support for time: you can't create a Time field on an SObject and therefore apex:inputField doesn't render a nice time selection widget. There is an Apex Time class but that doesn't help very much. I built a booking system for a charity and ended up using picklists for the class start times because the classes ...


2

Easiest way would be to create a new formula field on Contact, with type Date, referring the Date field on Account. The formula would be: Account.Account__Expiry__c The new formula field will then appear in the dropdown.


2

BusinessHours.isWithin(businessHoursId, targetDate); Documentation


2

Server time is in CST. Stack 4 is on Mountain Time. Daylight savings is not observed. What is the system timezone in Marketing Cloud and does it consider DST?


2

Yes, unfortunately second precision is as close as you can get, especially for audit fields (created date, last modified date). Using getTime will allow you to get closer to millisecond precision, so you may want to use that method when you need the extra precision. Strictly speaking, though, you can't control the order of things like triggers, so there ...


2

This is probably a bug, and I'd recommend contacting Salesforce Support (If you haven't already). Heres a repo I wrote using a custom object (Test__c, with a single time field, Some_Time__c). It starts with the a demo using Time as the object, then runs the same code for Test__c. The raw Time object works, and has the same syntax as the JSON, but the JSON ...


2

I was experiencing this same issue but managed to get the import to work by appending .000Z to the end of the hh:mm:ss format As an example: Start Time End Time 14:00:00.000Z 16:00:00.000Z 14:00:00.000Z 16:00:00.000Z 14:00:00.000Z 16:00:00.000Z 14:00:00.000Z 16:00:00.000Z 14:00:00.000Z 16:00:00.000Z 12:00:00.000Z 15:00:00.000Z Solution based ...


2

You can get exactly your desired output using the following: %%[ SET @time = "9/14/2019 4:37:57 PM" SET @formatted = Replace(FormatDate(@time, "YYYYMMDDT","HHMMSS"),' ','') ]%% %%=v(@formatted)=%% Output: 20190914T163757


2

Criteria are only evaluated at the moment a record is saved. This means that your rule only works if the user saves the record with the exact second in the reminder time field. Instead, make the criteria something like NOT(ISBLANK([PFL_Showing_OLD__c].Reminder_Time__c)), then set a Scheduled Action for "0 hours after Reminder Time". Your mistake was thinking ...


1

Tinkered around with this for a bit and here's one workable method. Have a field updated to today's date, have a second time based workflow activate 14 hours after today's date field. That will reliably kick off a process at 2pm according to your org time, whole hours only allowed unfortunately. For your second request though for a comparison of date time ...


1

You've closed your <apex:repeat> tag early. The only reason line2 is defined when you output its name is because you have defined it by your var attribute on that <apex:repeat>. Works <apex:repeat value="{!Opportunity.Invoices__r}" var="line2"> <!-- inside this repeat tag, line2 is defined --> {!line2.Name} <apex:...


1

You would want to use the BusinessHours.isWithin method, which requires a Datetime. You could do something as simple as: public with sharing class LeadSevice { static BusinessHours defaultHours { get { if (defaultHours == null) defaultHours = [SELECT Id FROM BusinessHours WHERE IsDefault = true]; ...


1

Z is number of hours your time zone is offset from UTC. Include the Z outside of the function if you want it included, or escape the character within the function with a backslash. Try: %%=FormatDate(DateAdd(NOW(), "6", "H"), "yyyy-mm-dd\T","hh:mm:ss\Z", "nl-NL")=%%


1

While NSjonas's answer does get you the correct result it does not follow Salesforce best practices and is thus incorrect. Users should minimize the number of functions being used when possible. To do this the proper formula should be: VALUE( MID( TEXT(NOW()) ,18,2) ) To solve the use case or for how to work with milliseconds please refer ...


Only top voted, non community-wiki answers of a minimum length are eligible