how can i make a function for day

 $thisplan = New-Object PSObject
Add-Member -InputObject $thisplan -MemberType NoteProperty -Name PlanID -Value $planid
Add-Member -InputObject $thisplan -MemberType NoteProperty -Name PlanName -Value $plan.name            
Add-Member -InputObject $thisplan -MemberType NoteProperty -Name SessionPassword -Value $sessionpass

 $schedule = $plan.backupConfiguration.advanceSchedule.periodSchedule 
    #DAY section #######
     add-Member -InputObject $thisplan -MemberType NoteProperty -Name DayRetention -Value $schedule.daySchedule.retentionCount
      if ($schedule.daySchedule.retentionCount -gt 0)
      {
        $dstart = udptime($schedule.daySchedule.dayTime)
      }
      else
      {
        $dstart = ""
      }
      Add-Member -InputObject $thisplan -MemberType NoteProperty -Name DayStart -Value $dstart
##########end day section######


is there a way to make a function for the #day section? This is a small part from my script.
the day section occurs several times in my script

Whatever code you want to be a function do this

Function NameOfFunction
{
code
}

Then whenever you want to run the function “NameOfFunction”

For organizational purposes, I like to put all my functions at beginning of the script.

how can i do it when the other block code is also in a function?

Are you asking if you can nest functions?

yea indeed

Sure you can and there is plenty documentation the shows this type of thing.
Yet, the question is, based on what you are after, should you nest.
As with many things. Just because you can do something, does not mean that you should.
Be cognizant of doing anything, unless you know what the outcome will be and / or have a very solid rationale as for why.