Date & Time Change

smartguy

Well-known Member
Joined
Jul 14, 2009
Messages
778
Hello All,

I have data in the below format.


Excel Workbook
A
14.2.2011 09:31:42 PM
24.2.2011 08:53:42 PM
34.2.2011 06:53:42 PM
44.2.2011 11:53:42 PM
Sheet1


I want to change the date and time based on 2 Condition.

No : 1

If time is after 9.30 p.m i want to change the date and time in to next day 12.31 p.M.

No : 2

if time is Before 12.31 P.M i want to change the date and time in to that day 12.31 P.M

Answer :

Excel Workbook
AB
14.2.2011 09:31:42 PM5.2.2011 12:31:00 PM
24.2.2011 08:53:42 PM4.2.2011 08:53:42 PM
34.2.2011 06:53:42 PM4.2.2011 06:53:42 PM
44.2.2011 11:53:42 PM4.2.2011 12:31:00 PM
Sheet1


Please help to provide the formula....
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
hmm, the two conditions contradict each other.

ex.
if it was:
4.2.2011 10:00:00 PM
should it become:
5.2.2011 12:31:00 PM
or:
4.2.2011 12:31:00 PM
 
Upvote 0
ah, I suffered from a bit of a stupidity on that one, sorry :biggrin:
don't have much experience in dealing with date/time formulas, but entering this formula into cell B2, should achieve what you want:
HTML:
=IF(TIME(21,31,0)<TIME(HOUR(A1),MINUTE(A1),SECOND(A1)),A1+DAY(1)-TIME(HOUR(A1),MINUTE(A1),SECOND(A1))+TIME(12,31,0),IF(TIME(12,31,0)>TIME(HOUR(A1),MINUTE(A1),SECOND(A1)),A1-TIME(HOUR(A1),MINUTE(A1),SECOND(A1))+TIME(12,31,0),A1))
<time(hour(a1),minute(a1),second(a1)),a1+day(1)-time(hour(a1),minute(a1),second(a1))+time(12,31,0),if(time(12,31,0)><time(hour(a1),minute(a1),second(a1)),a1+day(1)-time(hour(a1),minute(a1),second(a1))+time(12,31,0),if(time(12,31,0)><time(hour(a1),minute(a1),second(a1)),a1+day(1)-time(hour(a1),minute(a1),second(a1))+time(12,31,0),if(time(12,31,0)><time(hour(a1),minute(a1),second(a1)),a1+day(1)-time(hour(a1),minute(a1),second(a1))+time(12,31,0),if(time(12,31,0)><time(hour(a1),minute(a1),second(a1)),a1+day(1)-time(hour(a1),minute(a1),second(a1))+time(12,31,0),if(time(12,31,0)>
</time(hour(a1),minute(a1),second(a1)),a1+day(1)-time(hour(a1),minute(a1),second(a1))+time(12,31,0),if(time(12,31,0)></time(hour(a1),minute(a1),second(a1)),a1+day(1)-time(hour(a1),minute(a1),second(a1))+time(12,31,0),if(time(12,31,0)></time(hour(a1),minute(a1),second(a1)),a1+day(1)-time(hour(a1),minute(a1),second(a1))+time(12,31,0),if(time(12,31,0)></time(hour(a1),minute(a1),second(a1)),a1+day(1)-time(hour(a1),minute(a1),second(a1))+time(12,31,0),if(time(12,31,0)></time(hour(a1),minute(a1),second(a1)),a1+day(1)-time(hour(a1),minute(a1),second(a1))+time(12,31,0),if(time(12,31,0)>
 
Last edited:
Upvote 0
weird ...
why was it so difficult to paste the correct formula on here ...


You need to add spaces before and after < and > otherwise the board software interprets them as HTML tags and truncates the formula.
 
Upvote 0
You get a #VALUE! error presumably because A1 isn't a valid date/time, it's a text string.

Can you change A1 to a valid time/date? If you can then you can use this formula

=CHOOSE(MATCH(MOD(A1,1),{0,"12:31","21:30"}+0,0),"12:31",MOD(A1,1),"36:31")+INT(A1)

or with the current data try

=CHOOSE(MATCH(MOD(SUBSTITUTE(A1,".","/"),1),{0,"12:31","21:30"}+0),"12:31",MOD(SUBSTITUTE(A1,".","/"),1),"36:31")+INT(SUBSTITUTE(A1,".","/"))

custo format result cell as d.m.yy hh:mm:ss AM/PM
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,151
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top