Day,Month,Year Conversion

JDeMaro22
StarLounger
Posts: 94
Joined: 16 Oct 2021, 16:22

Day,Month,Year Conversion

Post by JDeMaro22 »

Hi,

I'm simply looking for the most convenient way to transform dates such as "Thursday, June 17, 2021" to "6/7/21. Is there a formula I can use for this?

Thanks,

Joshua

User avatar
HansV
Administrator
Posts: 78490
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Day,Month,Year Conversion

Post by HansV »

With such a text in D2:

=DATEVALUE(MID(D2,FIND(" ",D2,FIND(",",D2)+2)+1,FIND(",",D2,FIND(" ",D2,FIND(",",D2)+2)+1)-FIND(" ",D2,FIND(",",D2)+2)-1)&"-"&MID(D2,FIND(",",D2)+2,FIND(" ",D2,FIND(",",D2)+2)-FIND(",",D2)-2)&"-"&RIGHT(D2,4))

This can be filled down.
Best wishes,
Hans

User avatar
hamster
StarLounger
Posts: 58
Joined: 10 Mar 2021, 22:57

Re: Day,Month,Year Conversion

Post by hamster »

you can try Power Query

Code: Select all

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Inserted Parsed Date" = Table.AddColumn(Source, "Parse", each Date.From(DateTimeZone.From([date])), type date),
    #"Removed Other Columns" = Table.SelectColumns(#"Inserted Parsed Date",{"Parse"})
in
    #"Removed Other Columns"
d2d.png
You do not have the required permissions to view the files attached to this post.

User avatar
p45cal
2StarLounger
Posts: 149
Joined: 11 Jun 2012, 20:37

Re: Day,Month,Year Conversion

Post by p45cal »

More recent version of Excel?

Code: Select all

=DATEVALUE(TEXTJOIN("-",TRUE,INDEX(TEXTSPLIT(SUBSTITUTE(TRIM(D2),",","")," "),{3,2,4})))
or try:

Code: Select all

=DATEVALUE(CONCAT(INDEX(TEXTSPLIT(SUBSTITUTE(TRIM(D2),",","")," "),{3,2,4})))
edit 4th Aug 2021:
even shorter:

Code: Select all

=DATEVALUE(CONCAT(INDEX(TEXTSPLIT(TRIM(D2),{" ",","}),{4,3,6})))
Last edited by p45cal on 04 Aug 2023, 15:39, edited 4 times in total.

User avatar
p45cal
2StarLounger
Posts: 149
Joined: 11 Jun 2012, 20:37

Re: Day,Month,Year Conversion

Post by p45cal »

Hi-jacked hamster's workbook to add a named lambda version of my formula. See cell D2.
2023-08-03_114048.jpg
You do not have the required permissions to view the files attached to this post.

snb
4StarLounger
Posts: 577
Joined: 14 Nov 2012, 16:06

Re: Day,Month,Year Conversion

Post by snb »

A UDF:

Code: Select all

Function F_snb(c00)
  sn = Split(c00)
  F_snb = --Format(Val(sn(2)) & "-" & sn(1) & "-" & sn(3), "0")
End Function
In A1: "Thursday, June 17, 2021"

In a cell: =F_snb(A1)

User avatar
p45cal
2StarLounger
Posts: 149
Joined: 11 Jun 2012, 20:37

Re: Day,Month,Year Conversion

Post by p45cal »

Also:

Code: Select all

F_snb = CDate(Val(sn(2)) & "-" & sn(1) & "-" & sn(3))

snb
4StarLounger
Posts: 577
Joined: 14 Nov 2012, 16:06

Re: Day,Month,Year Conversion

Post by snb »

@p45

Quite right !

So even this will suffice:

Code: Select all

Function F_snb(c00)
  F_snb = CDate(Mid(c00, InStr(c00, " ")))
End Function