2

I made a sharepoint 2013 list in powershell, it has a date field, but I want the date field to be "Date Only" but I don't know how to do that in powershell code.

Does anyone know?

Thanks

enter image description here

EDIT:

$myFieldName = $myList.Fields.Add(“Date”, “DateTime”, 0)
$myList.Fields[$myFieldName ].Title = “Date”
$myList.Fields[$myFieldName ].Required = $true;
#$myList.Fields[$myFieldName ].Type = "DateOnly";
$myList.Fields[$myFieldName ].Update()
  • The property you're looking for is called "DisplayFormat" as you can see in my answer. – Andreas Dec 22 '15 at 18:03
6

It's fairly straight forward I would say.

// First get your field using the title from your list
$field = $list.Fields["FieldTitle"] 
// Alternativly you could use $list.Fields.GetFieldByInternalName("InternalFieldName")

$field.DisplayFormat = "DateOnly"
$field.Update()

I hope this helps.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.