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
rahul khan 6rahul khan 6 

how to remove date and only take time value using now function?

Best Answer chosen by rahul khan 6
Vaseem SVaseem S
Its simple...
what is your time zone format?
ours is +5:30 if we convert it to minutes its +330
in total day 24 hours if we convert it to minutes its 1440

so update your formula like this...

TIMEVALUE(NOW()+(330/1440))

in the place of 330 keep your timezone format converted into minutes.

Let me know if it works.

All Answers

Raj VakatiRaj Vakati
DateTime now = System.now();
Time t =now.time()

 
Raj VakatiRaj Vakati
DateTime now = System.now();

Time t =now.time();

System.debug('tt'+t);

 
rahul khan 6rahul khan 6
hi raj i need to create a formula field that just removes date from now() thats it not any coding kind of a thing
Raj VakatiRaj Vakati
You can use  TIMENOW function .. Still do you want time from date.now()??


The TIMENOW() function returns a value in GMT representing the current time without the date. Use this function instead of the NOW() function if you want the current hour, minute, seconds, or milliseconds. This value is useful for tracking time like work shifts or elapsed time,
Raj VakatiRaj Vakati
Use this
 
IF(
  OR(
    VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) ) = 0,
    VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) ) = 12
  ),
  "12",
  TEXT( VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) ) 
   -
   IF( 
     VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) ) < 12, 
     0, 
     12 
   ) 
  )
)
& ":" &
MID( TEXT( date/time - TZoffset ), 15, 2 )
& ":" &
MID( TEXT( date/time - TZoffset ), 18, 2 )
& " " &
IF(
  VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) ) < 12,
  "AM",
  "PM"
)


https://developer.salesforce.com/docs/atlas.en-us.usefulFormulaFields.meta/usefulFormulaFields/formula_examples_dates.htm

https://success.salesforce.com/answers?id=9063A000000iU8pQAE
Ajay K DubediAjay K Dubedi
Hi Rahul,

Below code can fulfill your requirements, Hope this will work for you.

type 1 :

DateTime dt = DateTime.now();
string stringDate = dt.hour() + ':' + dt.minute() +  ':' + dt.second();
System.debug(stringDate);

type 2 :

DateTime dt = DateTime.now();
System.debug(dt.time());

type 3:

Time as a string in “HH:MM:SS A/PM” format, use the following formula:

IF( OR( VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) ) = 0, VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) ) = 12 ), "12", TEXT( VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) ) - IF( VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) ) < 12, 0, 12 ) ) ) & ":" & MID( TEXT( date/time - TZoffset ), 15, 2 ) & ":" & MID( TEXT( date/time - TZoffset ), 18, 2 ) & " " & IF( VALUE( MID( TEXT( date/time - TZoffset ), 12, 2 ) ) < 12, "AM", "PM" )

Please mark this as best answer if this solves your problem.

Thank you,
Ajay Dubedi    



 
rahul khan 6rahul khan 6
my now() function should act like timenow() but should display local time not in GMT in a new formula field
Vaseem SVaseem S
Hello,

You have to select Time data type in formula to create and use

TIMEVALUE(NOW())

I hope it will help you.
rahul khan 6rahul khan 6
hey vaseem the formula you specified will give the time in GMT i want local time...
rahul khan 6rahul khan 6
User-added imageFrom time extractor field i have to remove date and just show current local time please help me out..
Vaseem SVaseem S
Its simple...
what is your time zone format?
ours is +5:30 if we convert it to minutes its +330
in total day 24 hours if we convert it to minutes its 1440

so update your formula like this...

TIMEVALUE(NOW()+(330/1440))

in the place of 330 keep your timezone format converted into minutes.

Let me know if it works.
This was selected as the best answer